GridBagLayout is one of the most important layout managers in Java, can make a very complex layout, can say that gridbaglayout is necessary to learn,GridBagLayoutClass is a flexible layout manager that does not require components to be of the same size to align components vertically, horizontally, or along their baselines.Each GridBagLayout object maintains a dyn
, all components must change with the size of the windowChange. Second, when we simply makeWhen xylayout is used, a large library must be included,For some occasionsThese extra classes exceedAcceptable range (for example, Applet Application)A simple interface is provided for introduction.1. First, create a jframe and set its layout to xylayout.2. Stack the control on it and align the position. Otherwise, the conversion will be greatly adjusted.3. Afte
GridBagLayout layout implements the simple email sending interface and gridbaglayout Layout
Grid Block Layout (GridBagLayoutIn JAVA, it is the most complex and powerful. It is developed on the basis of GridLayout. This layout also divides the entire container into several rows and columns, but each row can have different heights and different widths. One part can occupy one, it can also occupy multiple cell
Ashamed to say, using swing for nearly 2 years, has not studied the famous layout manager GridBagLayout in swing, said he is famous because he is flexible layout, can apply a variety of complex layout requirements, and of course because he is famous for the complex, this time due to a few days an important interview, " Forced "I have to study a bit (haha, the former is too lazy, I must pay more attention later."
First to share my study results, some i
Java FlowLayout, BorderLayout, GridLayout, GridBagLayout, and CardLayout layout manager
1. FlowLayout layout manager
FlowLayout ()Construct a new FlowLayout, which is centered and aligned. The default horizontal and vertical gaps are 5 units.
FlowLayout (int align)Construct a new FlowLayout with the specified alignment. The default horizontal and vertical gaps are 5 units.
FlowLayout (int align, int hgap, int vgap)Create a new flow layout manager wi
are public member variables of gridbagconstraints:Public int anchorPublic int fillPublic gridheightPublic gridweightPublic girdxPublic gridyPublic insetsPublic int ipadxPublic int ipadyPublic double weightxPublic double weightyIt seems that many constraints need to be set, but in fact many constraints only need to be set once and reused for multiple components. Only a few items need to be modified each time a component is added.The following is an example
allocate the remaining space of the row.
Weighty: weight of a column. This attribute determines how to allocate the remaining space of the column.
1. Make it clear that each gridbaglayout object maintains a dynamic rectangular cell grid. Each component occupies one or more of these cells, which are called display areas.The overall direction of the Grid depends on the componentorientation attribute of the container. For the horizontal orientation f
Gidbaglayout:(1) gridbagconstraints. gridwidthgridbagconstraints. gridheightSpecify the number of units in the display area row (for gridwidth) or column (for gridheight) of the component. The default value is 1. The following is an example of adding a button that occupies two cells (two rows and one column) to the window:Jframe F = new jframe ();Gridbaglayout gridbag = new
GridBagLayout is similar to GridLayout, but it is more flexible and complex, because the width and height values of each unit can be different. GridBagLayout uses the constraints of GridBagLayoutConstraints to add constraints to components. There are several important parameters for GridBagLayoutConstraints. We only need to understand this, and the rest will be easy.
1: gridx, gridy:
This indicates the hori
This is only a very basic layout of the construction and use, mainly about GridBagLayout.First the whole process is probably,Declares a GridBagLayout objectPrivate GridBagLayout Gridbaglayoutframe = new GridBagLayout ();Then set the container layout manager of the current class to GridBagLayoutThis.setlayout (Gridbaglayoutframe);Finally, declare a JPanel for addi
JAVA GridBagLayout layout manager application details, javatedbaglayout
In many cases, you do not need to write code to implement a graphical interface of an application. Instead, you can easily use a powerful IDE tool to drag and drop the Code with simple event processing code. However, we have to deal with some problems in this operation. Sometimes we want to freely change the size of a program interface. The interface generated by the drag-and-drop
GridBagLayout is one of the most important Java layout manager, can make a very complicated layout, can say GridBagLayout is must learn,
GridBagLayoutClass is a flexible layout manager that does not require the same size of components to align components vertically, horizontally, or along their baselines.
Each GridBagLayout object maintains a dynamic rectangula
= 0.0;//Reset to the default $C.gridwidth = Gridbagconstraints.remainder;//End Row -C.gridheight = 1;//Reset to the default -Makebutton ("Button9", Gridbag, c); -Makebutton ("Button10", Gridbag, c); A +SetSize (300, 100); the } - $ Public Static voidMain (String args[]) the { theJFrame f =NewJFrame ("Gridbag Layout Example"); theF.setlocation (400, 200); theGRIDBAGEX2 Ex1 =NewGridBagEx2 (); - in ex1.init (); the theF.add ("Center", E
Tags: style color io sp on problem code EF BSIn swing, we generally set the form size with the setSize () method, and this method is really useful. But when it comes to layout, especially when the complex layout is gridbaglayout and the window is not small, this method does not work. If you haven't tried it, you can try it.So what should we do?Very simple, first check the code there is no very basic error, if not, then as long as the SetSize () method
If you want the effect of button 2 to be two lines , you must press 3, Button 4 is present and visible at the same time.
If button 4 is missing, Button 2 does not occupy two lines;
If button 3, 4 is missing, then button 2 does not take up two lines.
1 PackageCOM.WST.BJ;2 3 Importjava.awt.GridBagConstraints;4 Importjava.awt.GridBagLayout;5 6 ImportJavax.swing.JButton;7 ImportJavax.swing.JFrame;8 9 classGridbagtext {Ten OneJFrame JFrame =NewJFrame ("Search"); A -JButton J
Gridbaglayout can be used to implement a complex and controllable layout.
Take an input box as an example:
Gridbagconstraints is used to define the position arrangement information of components.
The final effect is as follows:
You can change the length of the input box to 200.
For details about gridbagconstraints, see gridbagconstraints
1. the following example shows how to add a split line to the grid layout panel: [java] GridBagConstraints grid4 = new GridBagConstraints (); grid4.gridx = 3; grid4.gridy = 0; grid4.fill = GridBagConstraints. VERTICAL; grid4.insets = new Insets (0, 5, 0, 5); JSeparator separator4 = new JSeparator (); // create a VERTICAL separator separator4.setOrientation (JSeparator. VERTICAL); [java] container. add (separator4, grid4); remove grid4.fill = GridBagCo
1.GridBagLayoutThe layout manager is very flexible and GridBagLayout maintains a dynamic rectangular cell grid for each object;2. Need to be used in conjunction with its constraint class (Gridbagconstraints class);3. GridBagLayout provide a way for the components to be laid out, and the specific constraints are gridbagconstraints to be implemented;4. Complete a flexible layout manager by invoking the variou
();p 2.setLayout (New GridLayout (3,5,4,4)); String[] name = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "."}; for (int i = 0; i Iv. GridBagLayout Layout ManagerTo use GridBagLayout, you must use the Gridbagconstraints object to specify the location of the components in the gridbaglayout.The Setconstraints method of the GridBagLayout c
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.