Java基础之创建窗口——使用边界布局管理器(TryBorderLayout)
控制台程序。
边界布局管理器最多能在容器中放置5个组件。在这种布局管理器中,可以把组件放在容器的任意一个边界上,也可以把组件放在容器的中心。每个位置只能放置一个组件。如果把组件放置在已被占用的边界上,前一个组件就会被取代。要选择边界,应指定约束,约束可以是NORTH、SOUTH、EAST、WEST或CENTER。它们都是BorderLayout类中定义的final static常量。
import javax.swing.*;
import javax.swing.SwingUtilities;
import java.awt.*;
import javax.swing.border.EtchedBorder; public class TryBorderLayout { public static void createWindow(){
JFrame aWindow = new JFrame("This is the Window Title");
Toolkit theKit = aWindow.getToolkit(); // Get the window toolkit
Dimension wndSize = theKit.getScreenSize(); // Get screen size // Set the position to screen center & size to half screen size
aWindow.setSize(wndSize.width/2, wndSize.height/2); // Set window size
aWindow.setLocationRelativeTo(null); // Center window
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BorderLayout border = new BorderLayout(); // Create a layout manager
Container content = aWindow.getContentPane(); // Get the content pane
content.setLayout(border); // Set the container layout mgr
EtchedBorder edge = new EtchedBorder(EtchedBorder.RAISED); // Button border // Now add five JButton components and set their borders
JButton button;
content.add(button = new JButton("EAST"), BorderLayout.EAST);
button.setBorder(edge);
content.add(button = new JButton("WEST"), BorderLayout.WEST);
button.setBorder(edge);
content.add(button = new JButton("NORTH"), BorderLayout.NORTH);
button.setBorder(edge);
content.add(button = new JButton("SOUTH"), BorderLayout.SOUTH);
button.setBorder(edge);
content.add(button = new JButton("CENTER"), BorderLayout.CENTER);
button.setBorder(edge); aWindow.setVisible(true); // Display the window
} public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createWindow();
}
});
}
}
Java基础之创建窗口——使用边界布局管理器(TryBorderLayout)的更多相关文章
- Java基础之创建窗口——使用网格布局管理器(TryGridLayout)
控制台程序. 网格布局管理器可以在容器的矩形网格中布局组件. import javax.swing.*; import java.awt.*; import javax.swing.border.Et ...
- Java基础之创建窗口——使用卡片布局管理器(TryCardLayout)
控制台程序. 卡片布局管理器会生成一叠组件——一个组件放在另一个组件的上面.添加到容器中的第一个组件在堆栈的顶部,因此是可见的,添加的最后一个组件在堆栈的底部.使用默认的构造函数CardLayout( ...
- JAVA 边界布局管理器
//边界布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian1 extends JFrame{ //定义组件 JBut ...
- java边界布局管理器
public class BorderLayoutPosition extends JFrame{ String[] border={BorderLayout.CENTER,Border ...
- Java基础之创建窗口——使用GridBagLayout管理器(TryGridBagLayout)
控制台程序. java.awt.GridBagLayout管理器比前面介绍的其他布局管理器灵活得多,因此使用起来也比较复杂.基本机制就是在随意的矩形网格中布局组件,但网格的行和列不一定拥有相同的高度和 ...
- Java基础之创建窗口——使用BoxLayout管理器(TryBoxLayout4)
控制台程序. javax.swing.BoxLayout类定义的布局管理器在单行或单列中布局组件.创建BoxLayout对象时,需要指定是在行还是列中布局组件. 对于行,组件是从左到右地添加:对于列, ...
- Java基础之创建窗口——使用SpringLayout管理器(TrySpringLayout)
控制台程序. 可以把JFrame对象aWindow的内容面板的布局管理器设置为javax.swing.SpringLayout管理器. SpringLayout类定义的布局管理器根据javax.swi ...
- Java基础之创建窗口——使用流布局管理器(TryFlowLayout)
控制台程序. FlowLayout把组件放在容器的连续行中,使每一行都放置尽可能多的组件.如果某行已满,就放在下一行.工作方式类似于文本处理器把单词放在行中.主要用途是放置按钮,但也可以用来放置其他组 ...
- java图形用户界面边界布局管理器
总结:不同方向的组件,所用的板是不同的: package com.moc; //用布局写一个界面 ///运用边界布局 //2个按钮在北,2个按钮在南 //中央一个大按钮 //将同一方向的组件封装后布局 ...
随机推荐
- [SHELL实例] (转)最牛B的 Linux Shell 命令 (一)
本文编译自commandlinefu.com ( 应该是 Catonmat ) 的系列文章 Top Ten One-Liners from CommandLineFu Explained .作为一个由 ...
- PHP正则表达式及实例
PHP正则表达式及实例 博客分类: Php / Pear / Mysql / Node.js 正则表达式PHPWordPressFPApache 关联: 正则表达式 去除连续空白 + 获取url + ...
- 【IOS笔记】Delegation
Delegation Delegation is a simple and powerful pattern in which one object in a program acts on beha ...
- C#winfrom中splitContainer的用法
常用属性 (1).splitContainer不能被鼠标直接点击选中,可通过右击->选择splitContainer选中. (2).属性IsSplitterFixed用于设置拆分器能否移动. ( ...
- data-"mit.edu-Thinking In C++"
Volume 2 ctrl+s http://web.mit.edu/merolish/ticpp/TicV2.html http://web.mit.edu/merolish/ticpp/TicV2 ...
- 【php学习】时间函数
手工画了一张图,来大体概括php中对于时间的处理函数 首先时间戳是这样“1441202665”的一串数字,虽然人看起来麻烦,但是计算机却很容易识别这样的时间表示形式. 所以给计算机看的时间是时间戳,给 ...
- phpcms标签整理_当前栏目调用
phpcms标签整理_当前栏目调用 转载 **//SQL语句调用: {pc:get sql="select * from phpcms_category where catid in($ca ...
- CGROUP
二:cgroup中的概念在深入到cgroup的代码分析之前.先来了解一下cgroup中涉及到的几个概念:1:cgroup: 它的全称为control group.即一组进程的行为控制.比如,我们限制进 ...
- C/C++ 笔试、面试题目大汇总
1.求下面函数的返回值( 微软) int func(x) { int countx =0; while(x) { countx ++; x = x&(x-1); } return countx ...
- ArcGIS Engine开发的ArcGIS 版本管理的功能
原文:ArcGIS Engine开发的ArcGIS 版本管理的功能 转自:http://blog.csdn.net/linghe301/article/details/7965901 这是以前的Arc ...