Hi Guys,

Basically, I'm writing a Sudoku solver and its the first time I've come into contact with the interface package SWING in Java, or any interface package! So far I've been using a 9x9 "GridLayout" within a "JPanel" displaying "JTextFields" (blank so far!)...I'd like to make it so that there is a definition between the sub blocks(3x3 matrices) and I can't work it out. Does anyone know how to create say a thick line to separate the sub blocks?..or if anyone could think of a better idea that would be great ...Thanks

Sarah

A suggestion for an easy way to do it: int rows = 3;

int columns = 3;

JPanel mainPanel = new JPanel(new GridLayout(rows, columns));JPanel[] subPanels = null;

Border outerBorder = BorderFactory.createLineBorder(Color.black, 5);

Border innerBorder = BorderFactory.createLineBorder(Color.black, 1);mainPanel.setBorder(outerBorder);

subPanels = new JPanel[rows*columns];

for (int r = 0; r < rows; r++) {

for (int c = 0; i < columns; c++) {

subPanels[r*c] = new JPanel(new GridLayout(rows, columns);

subPanels[r*c].setBorder(innerBorder);

mainPanel.add(subPanels[r*c]);

}

}// now have 3 x 3 with each cell having a 3 x 3 (so 9 X 9)

If you have any questions email me at tom_markel@markelsoft.com

xx

A suggestion for an easy way to do it: int rows = 3;

int columns = 3;

JPanel mainPanel = new JPanel(new GridLayout(rows, columns));JPanel[] subPanels = new JPanel[rows, columns];

JPanel[rows*columns][rows*columns] sub2Panels = null;

Border outerBorder = BorderFactory.createLineBorder(Color.black, 5);

Border innerBorder = BorderFactory.createLineBorder(Color.black, 1);mainPanel.setBorder(outerBorder);

for (int r = 0; r < rows; r++) {

for (int c = 0; i < columns; c++) {

subPanels[r*c] = new JPanel(new GridLayout (rows, columns);

subPanel[r*c].setBorder(outerBorder);for (int r2 = 0; r2 < rows; r2++) {

for (int c2 = 0; c2 < columns; c2++) {

sub2Panels[r2][c2] = new JPanel();

sub2Panels[r2][c2].setBorder(innerBorder);

subPanels[r*c].add(sub2Panels[r2][c2]);

}

}

}

mainPanel.add(subPanels[r*c]);

}// now have 3 x 3 with each cell having a 3 x 3 (so 9 X 9)

If you have any questions email me at tom_markel@markelsoft.com

xx

Ask Your Question

Weekly Poll

Do you think the new NOOK by Samsung will save the NOOK brand?

Discuss in The Lounge

Poll History