0

I am doing a euromillion program and i need some help. I have this code and i would like to set a size for the JButton. I dont know how to do it

Can someone tell me what do i have to change?

static JButton[][] botoes = new JButton[5][10];
static JButton [][] estrelas = new JButton[4][3];

public void grafica(){
    GridLayout layoutBotoes = new GridLayout(5,10);
    GridLayout layoutEstrelas = new GridLayout(4,3);
    um.setLayout(layoutBotoes);
    dois.setLayout(layoutEstrelas);
    for(i=0;i<5;i++){  
        for(l=0;l<10;l++){  
            cont++;
            botoes[i][l] = new JButton(""+cont);
            um.add(botoes[i][l]); 
            botoes[i][l].addActionListener(this);
        } 
    }  
    cont=0;
    for(i=0;i<4;i++){  
        for(l=0;l<3;l++){ 
            if(i==3 && l==2) {
                break;
            } else {
                cont++;
                estrelas[i][l] = new JButton(""+cont); 
                dois.add(estrelas[i][l]); 
                estrelas[i][l].addActionListener(this);
            }
        }
    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • what _exactly_ do you want to achieve? – kleopatra Apr 14 '13 at 10:43
  • i want to put a size for the JButton – user2279348 Apr 14 '13 at 10:47
  • 2
    no, that's not what you want :-) In Swing/AWT, sizing and locating is the task of the LayoutManager, always. Your tasks are a) define the visuals of your ui (relative positioning/alignment/resizing behehaviour) b) find a LayoutManager that suits your requirements – kleopatra Apr 14 '13 at 10:51
  • i dont get it! My jButton are to big i want them smaller – user2279348 Apr 14 '13 at 10:56
  • 1
    read the tutorial chapter on LayoutManager (click the tab "info" and follow the swing tutorial link) to understand which manager does what (hint: GridLayout makes all components the same size and uses all the space available) – kleopatra Apr 14 '13 at 10:58

1 Answers1

1

You might be able to use one of the approaches shown here or here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045