Jump to content

GridBagLayout

- - - - -

  • Please log in to reply
1 reply to this topic

#1
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I donw understand what the gridwith makes in Java GUI:


  JFrame f = new JFrame("DF");   f.setSize(400, 200); f.setLocation(300,300); 

          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


		   Container pane=f.getContentPane();

		  pane.setLayout(new GridBagLayout());

		  

		  GridBagConstraints gbc=new GridBagConstraints();

		  

		  gbc.gridx=1; 		  

		  gbc.gridy=GridBagConstraints.RELATIVE;

		  

          pane.add(new JButton("AAA"), gbc);

          pane.add(new JButton("b"), gbc); // "B" must be below the A

          

         gbc.gridwidth=2;

         pane.add(new JButton("c"), gbc);  // now C must be next to the "A"

          

          gbc.gridwidth=1;

          gbc.gridx=GridBagConstraints.RELATIVE;

          pane.add(new JButton("DDD"), gbc); 

I don't understand
1) what does the gbc.gridwidth=2 and gbc.gridwidth=1 means?
2) why is "DDD" next to the A?
3) why is C Centered horizontally?
4) how to set border color to the table colums and rows here?...

please explane me what does gridwith and gridheight makes.
GNU/Linux Is the Best.

#2
farrell2k

farrell2k

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
I can tell you that GridBagConstraints.gridWidth and gridHeight represent the number of cells in a row or column. There are much easier ways to lay out a gui. Leave these unnecessarily complicated layout managers to Netbeans Matisse.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users