Buttons matrix

G

Guest

Hi all,

I have an AWT problem. I'd like to add some Buttons to a Panel (with a
GridLayout of
dynamic dimension). Practically when I click on button1 it should
happens this:

void button1_actionPerformed(ActionEvent e) {
int n=4;
this.gridLayout1.setRows(n);
this.gridLayout1.setColumns(n);
Button[][] buttonMatrix=new Button[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
buttonMatrix[j]=new Button(".");
buttonMatrix[j].setBackground(new Color(124324));
panelMatrix.add(buttonMatrix[j]);
panelMatrix.validate();
panelMatrix.repaint();
}
}
}

where I set n=4, but it could be set to any value.
But, the applet I'm writing doesn't works like I'd like to: when I
click on button1 it doesn't
happens anything, I don't see the buttons in panelMatrix (although
there is no exception
thrown).
Anyone can help?

Thanks,

Pierre Blanc


------------------------------------------------------------
http://www.teutoburgo.tk
Teutoburgo - A forest to navigate

http://www.site-map.tk
Site Map Generator
 
V

Vova Reznik

Hi all,

I have an AWT problem. I'd like to add some Buttons to a Panel (with a
GridLayout of
dynamic dimension). Practically when I click on button1 it should
happens this:

void button1_actionPerformed(ActionEvent e) {
int n=4;
this.gridLayout1.setRows(n);
this.gridLayout1.setColumns(n);
Button[][] buttonMatrix=new Button[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
buttonMatrix[j]=new Button(".");
buttonMatrix[j].setBackground(new Color(124324));
panelMatrix.add(buttonMatrix[j]);
panelMatrix.validate();
panelMatrix.repaint();
}
}


You need to revalidate Applet, not only panelMatrix

applet.validateTree();

or you may change default LayoutManager for Applet (FlowLayout) to
forexample BorderLayout and add panelMatrix
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top