开发者

Java - Is it possible to have two components on the same side with GridLayout?

Java - Is it possible to have two components on the same side with GridLayout?

Is it possible to have the "Save note" button under the "Create note" button using GridLayout? If not, what layout should I be using? dataPanel contains both text fields and both labels. buttonPanel is the save note button and namePanel is the create note button.

    container.add(dataPanel, BorderLayout.CENTER);
    container.add(butt开发者_如何学ConPanel, BorderLayout.SOUTH);
    container.add(namePanel, BorderLayout.EAST);

Thanks in advance!


Of course it is possible! Simply define a grid layout with 2 rows and 3 columns each: - first column will contain the labels - second column will contain the text boxes - 3rd column will contain the buttons

Also, why are you using the BorderLayout constants when adding to the GridLayout? With GridLayout once you have decided on the rows/columns simply add them in the order you want them to be layed out in the "grid" from left to right, top to bottom. So in the above example you will do something like this:

JPanel p = new JPanel( new GridLayout(2,3) );
p.add( /* enter the desired note label */ );
p.add( /* note name here text box */ );
p.add( /* create note button */ );
p.add( /* enter a new note label */ );
p.add( /* note text here text box */ );
p.add( /* save note button */ );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜