Hie , I am adding three buttons to my frame but when I am running the code , the buttons do not have uniform width. Can someone help me out.- I need ideas on how to make btnA,btnB and btnC have the same width. The code is not giving errors when I run it. The code is
NB: My class extends JFrame
NB: My class extends JFrame
Code:
Container cont=getContentPane(); JPanel panel=new JPanel(new GridBagLayout()); GridBagConstraints gbc= new GridBagConstraints(); gbc.weighty=0.5; //gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=0.5; gbc.gridx=0; gbc.gridy=0; btnA=new JButton("AAAAA AAAAA"); panel.add(btnA,gbc); gbc.gridy=1; btnB = new JButton("BBBB BBBBBBBBB"); gbc.gridy=2; panel.add(B,gbc); btnC=new JButton("CCCCCCCCC"); gbc.gridy=3; panel.add(btnC,gbc); setSize(300,200); cont.add(panel); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Comment