This is only a very basic layout of the construction and use, mainly about GridBagLayout.
First the whole process is probably,
Declares a GridBagLayout object
Private GridBagLayout Gridbaglayoutframe = new GridBagLayout ();
Then set the container layout manager of the current class to GridBagLayout
This.setlayout (Gridbaglayoutframe);
Finally, declare a JPanel for adding components. (It could be another panel, of course.) such as JTabbedPane, etc.)
Private JPanel Checkboxtreepanel = new JPanel ();
Private JTabbedPane TabbedPane = new JTabbedPane ();
You can then start using this layout manager to add and set up components.
|
add(Component comp, Object constraints) |
Here is an example:
1 Importjava.awt.*;2 ImportJavax.swing.JFrame;3 ImportJavax.swing.JTabbedPane;4 ImportJavax.swing.JPanel;5 6 7 Public classWriteforblogextendsJFrame8 {9 PrivateGridBagLayout Gridbaglayoutframe =Newgridbaglayout ();Ten PrivateJTabbedPane TabbedPane =NewJTabbedPane (); One PrivateJPanel Panelone =NewJPanel (); A PrivateJPanel Paneltwo =NewJPanel (); - - PublicWriteforblog () the { - jbinit (); - } - + Private voidJbinit () - { + This. setlayout (gridbaglayoutframe); A This. setbounds (200, 200, 1000, 600); atTabbedpane.add (Panelone, "one"); -Tabbedpane.add (Paneltwo, "the other"); - - This. Add (TabbedPane,NewGridbagconstraints (0, 0, 1, 1, 1.0, 1.0 -, Gridbagconstraints.northwest, Gridbagconstraints.both,NewInsets (0, 0, 0, 0), 0, 0)); - } in - Public Static voidMain (string[] args) to { +Writeforblog test =NewWriteforblog (); -Test.setvisible (true); the } * $}
:
Java GridBagLayout Simple to use