java布局管理器(Java中布局管理器怎么应用)

本文目录
- Java中布局管理器怎么应用
- java中怎么设置布局管理器
- JAVA中提供了几种布局管理器简述他们之间的区别紧急
- java布局管理器有哪几种各自的特点
- 在java中GroupLayout这个布局管理器的中文名叫什么绝对布局又应该怎么设置
- java中布局管理器有几种 都有什么
Java中布局管理器怎么应用
没几个东西,setLayout(null),一个一个画吧
你可以用多个管理器一起使用,或将TextField与TextArea设置为固定的大小
java中怎么设置布局管理器
import java.applet.Applet;
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class GridBagEx extends Applet
{
private static final long serialVersionUID = 1L;
protected void makebutton ( String name, GridBagLayout gridbag, GridBagConstraints c )
{
Button button = new Button (name);
gridbag.setConstraints (button, c);
add (button);
}
public void init ()
{
GridBagLayout gridbag = new GridBagLayout ();
GridBagConstraints c = new GridBagConstraints ();
setFont (new Font (“SansSerif“, Font.PLAIN, 14));
setLayout (gridbag);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
makebutton (“Button1“, gridbag, c);
makebutton (“Button2“, gridbag, c);
makebutton (“Button3“, gridbag, c);
c.gridwidth = GridBagConstraints.REMAINDER; // end row
makebutton (“Button4“, gridbag, c);
c.weightx = 0.0; // reset to the default
makebutton (“Button5“, gridbag, c); // another row
c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last in row
makebutton (“Button6“, gridbag, c);
c.gridwidth = GridBagConstraints.REMAINDER; // end row
makebutton (“Button7“, gridbag, c);
c.gridwidth = 1; // reset to the default
c.gridheight = 2;
c.weighty = 1.0;
makebutton (“Button8“, gridbag, c);
c.weighty = 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);
setSize (300, 100);
}
public static void main ( String args )
{
Frame f = new Frame (“GridBag Layout Example“);
GridBagEx ex = new GridBagEx ();
ex.init ();
f.add (ex);
f.pack ();
f.setLocationRelativeTo (null);
f.addWindowListener (new WindowAdapter ()
{
@Override
public void windowClosing ( WindowEvent e )
{
System.exit (0);
}
});
f.setVisible (true);
}
}
JAVA中提供了几种布局管理器简述他们之间的区别紧急
java中提供了5种布局管理器,1.Borderlayout 这是一个布置容器的边框布局,它可以对容器组件进行安排,并调整其大小,使其符合下列五个区域:北、南、东、西、中。每个区域最多只能包含一个组件;2.Flowlayout 这个按照上面横排布局,流布局用于安排有向流中的组件,这非常类似于段落中的文本行;3.Gridlayout 它以矩形网格形式对容器的组件进行布置。容器被分成大小相等的矩形,一个矩形中放置一个组件;4.Cardlayout 它将容器中的每个组件看作一张卡片。一次只能看到一张卡片,容器则充当卡片的堆栈。当容器第一次显示时,第一个添加到 CardLayout 对象的组件为可见组件;5.Boxlayout 允许垂直或水平布置多个组件的布局管理器。这些组件将不包装,因此举例来说,垂直排列的组件在重新调整框架的大小时仍然被垂直排列。 用水平组件和垂直组件的不同组合嵌套多面板的作用类似于 GridBagLayout,但没那么复杂。该图显示了两个水平排列的面板,每个面板都包含 3 个垂直排列的组件。
java布局管理器有哪几种各自的特点
大概讲简单的三种:
①FlowLayout流布局管理器,它的布局方式是在一行上排列组件,当一行没有足够空间时,则回行显示,默认为居中
②BorderLayout边界布局管理器,它的布局方式是将容器划分为5个部分
③GridLayout网格布局管理器,它的布局方式是将容器按照用户设置平均划分成若干网格
在java中GroupLayout这个布局管理器的中文名叫什么绝对布局又应该怎么设置
先说第一个问题,GroupLayout中文叫群组布局。
再说第二个问题,使用绝对布局需要对组件所在的窗体容器中取消使用布局管理:setLayout(null);
然后将你所要添加的组件分别设置其大小(setSize(w,h))和位置(setLocation(x,y)),就可以了。
java中布局管理器有几种 都有什么
java是与平台无关的,什么叫与平台无关呢,就是应用程序的界面的大小,位置与硬件没关系,与平台无关就是说你不能通过setsize()这样的方法去设置窗体中组件的大小。由此问题产生了。
当一个窗体中有文本控件,又有标签,还有按钮,这时你怎么控制它们在窗体中的排列顺序和位置呢,java定义了布局管理器来处理这个问题
这就是布局管理器的作用

更多文章:
turtles歌曲(哪位大神有turtles(乌龟组合)的<谢谢>的歌词中文翻译 感激不尽)
2026年10月11日 10:00
金山铁路22号线(请问现在轨道交通22号线金山铁路是个什么情况据说9月28日就开通了啊~~~)
2026年10月11日 09:10
repercussions(都是余波,repercussions和aftermath有什么区别啊)
2026年10月11日 09:00
dropdownlist 绑定(DropDownList 绑定所有项 并 显示指定项)
2026年10月11日 08:50
易语言网页api接口怎么调用(易语言,怎么读取网页json的api)
2026年10月11日 08:00
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40



