Java GridBagLayout Simple to use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.