GridBagLayout not working as expected

i was coding Address Book GUI using GridBagLayout . problem is that when i set gridx and gridy that does not work it looks as there is no layout used and components fall in center of the Frame . i am not pasting whole code just a small piece of code for 1 `JButton` to let you see what is happening .. please see the code and gudide me how to fix it , right now button is falling in center of the `JFrame` I am just beginner so please dont mind if foolish style code or any problem like that public class rect { JFrame frame ; JPanel panel1 ; JButton b1; GridBagConstraints gbc; public rect() { panel1 = new JPanel(); panel1.setSize(300,300); panel1.setLayout(new GridBagLayout()); gbc = new GridBagConstraints(); frame= new JFrame("Address ?ooK "); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); b1= new JButton () ; b1.setText("Hello "); gbc.gridx=1; gbc.gridy=0; panel1.add(b1, gbc) ; frame.add(panel1); panel1.setVisible(true); frame.setVisible(true); }
Where is it supposed to be? Try to set weightx/weight to 1.0 and change anchor to GridBagLayout.NORTH... and see what happens ;-) I recommend to carefully read GBL documentation and tutorial.

以上就是GridBagLayout not working as expected的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准