java布局管理器(java布局管理器有哪几种各自的特点)
本文目录
java布局管理器有哪几种各自的特点
大概讲简单的三种:①FlowLayout流布局管理器,它的布局方式是在一行上排列组件,当一行没有足够空间时,则回行显示,默认为居中②BorderLayout边界布局管理器,它的布局方式是将容器划分为5个部分 ③GridLayout网格布局管理器,它的布局方式是将容器按照用户设置平均划分成若干网格
java中布局管理器有几种 都有什么
java是与平台无关的,什么叫与平台无关呢,就是应用程序的界面的大小,位置与硬件没关系,与平台无关就是说你不能通过setsize()这样的方法去设置窗体中组件的大小。由此问题产生了。当一个窗体中有文本控件,又有标签,还有按钮,这时你怎么控制它们在窗体中的排列顺序和位置呢,java定义了布局管理器来处理这个问题这就是布局管理器的作用
JAVA中,Frame和Panel默认的布局管理器分别是什么类型
JAVA中,Framel默认的布局管理器是BorderLayout类型,Panel默认的布局管理器是FlowLayout类型。
FlowLayout是Panel 和 Applet 的默认布局管理器。在该布局管理器中,组件在容器中按照从上到下,从左到右的顺序进行排列,行满后则换行。
BorderLayout是Window、Frame和Dialog的默认布局管理器,其将容器分成North、South、East、West和Center 5个区域,每个区域只能放置一个组件。使用BorderLayout时,如果容器大小发生变换,组件的相对位置不变。
扩展资料:
其它相关的布局管理器:
1、网格布局管理器(GridLayout):
GridLayout 可使容器中的各个组件呈网格状布局,平局占据容器的空间,即使容器的大小发生变化,每个组件还是平均占据容器的空间。和FlowLayout一样,GridLayout也是按照从上到下,从左到右的规律进行排列的。
2、卡片布局管理器(CardLayout):
CardLayout能够帮助用户处理两个乃至跟多的成员共享同一显示空间。它把容器分成许多层,每层的显示空间占据整个容器的大小,并且每层之允许反之一个组件,可以通过Panel来实现每层复杂的用户界面。
参考资料来源:百度百科-JPanel
参考资料来源:百度百科-AWT
Java布局管理器问题
问题一:
自定义的类BorderLayout和 java.awt.BorderLayout 这个类同名了 , 需要修改.
比如修改成BorderLayoutDemo
问题二:
这些组件的复制粘贴 ,注意修改啊 ,jb1 ,jb2 ,jb2...jb2 , jb2添加了4次....
并且由于你的类名也叫BorderLayout ,所以BorderLayout.CENTER..等方位的值都是null.
缺省的状态下,都会放到中间. 最后的覆盖前面的.所以最后只显示出1个jb2.并且居中
修改后的效果图
修改的代码
import java.awt.BorderLayout;import javax.swing.JButton;import javax.swing.JFrame;//注意类名public class BorderLayoutDemo extends JFrame { // 定义组件 JButton jb1, jb2, jb3, jb4, jb5; public static void main(String args) { // TODO Auto-generated method stub BorderLayoutDemo bl = new BorderLayoutDemo(); } public BorderLayoutDemo() { // 创建组件 jb1 = new JButton(“中部“); jb2 = new JButton(“北部“); jb3 = new JButton(“东部“); jb4 = new JButton(“南部“); jb5 = new JButton(“西部“); // 添加组件 this.add(jb1, BorderLayout.CENTER); this.add(jb2, BorderLayout.NORTH); this.add(jb3, BorderLayout.EAST); this.add(jb4, BorderLayout.SOUTH); this.add(jb5, BorderLayout.WEST); // 设置窗口属性 this.setTitle(“边界布局案例“); this.setSize(500, 400); this.setLocation(600, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); }}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); }}
更多文章:
frequency函数(Excel-FREQUENCY函数)
2025年2月24日 17:30
喝牛奶时经常看到“巴氏杀菌”,那么这到底是什么,求科普?巴氏灭菌法对蜂蜜有用吗
2025年2月21日 20:30
details怎么删除窗口(validation failure details怎么删除这个)
2025年4月6日 00:20
java异常类(Java中异常类的作用为什么要进行异常处理,有什么好处)
2025年2月17日 09:00
win10激活工具永久激活(win10家庭版系统怎么永久激活呢)
2025年3月25日 17:00
everybody knows i love you(everybody know i love you这首歌的歌词)
2025年3月26日 07:50
lockdown用法(shutdown和lockdown的区别)
2025年3月31日 23:00
qpython3官方版下载(手机版qpython如何下载pygame)
2025年4月2日 01:10
漏洞利用工具(系统激活工具是怎么激活系统的它是怎么绕开微软的秘钥策略的)
2025年3月18日 04:30