java - How to position/lay out components on JPanel? -


i'm trying position 5 buttons on jframe. 4 buttons should in first row , fifth 1 should in second row. here of buttons appear in 1 row , half of fifth button out of panel. way if use frame.pack(); frame become smaller expected. don't want change size of frame. want locate fifth 1 in second row.

import java.awt.gridbaglayout; import java.awt.gridlayout;  import javax.swing.*;   public class test {      public static void main(string[] args) {           jframe frame = new jframe();         frame.setbounds(100, 100, 529, 300);         frame.getcontentpane().setlayout(new gridlayout(1, 0, 0, 0));           jpanel panel = new jpanel();         frame.getcontentpane().add(panel);         panel.setlayout(new boxlayout(panel, boxlayout.x_axis));           jbutton btnnewbutton_4 = new jbutton("new button");         panel.add(btnnewbutton_4);          jbutton btnnewbutton_3 = new jbutton("new button");         panel.add(btnnewbutton_3);          jbutton btnnewbutton = new jbutton("new button");         panel.add(btnnewbutton);          jbutton btnnewbutton_1 = new jbutton("new button");         panel.add(btnnewbutton_1);          jbutton btnnewbutton_2 = new jbutton("new button");         panel.add(btnnewbutton_2);           frame.setvisible(true);         frame.setdefaultcloseoperation(jframe.exit_on_close);       }  } 

four buttons should in first row , fifth 1 should in second row.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -