java中如何控制BOX里面的组件大小

你可以试试这个
panel.setPreferredSize(new Dimension(100,30));

㈡ java box的用法求例子

这是盒子布局 就像盒子一样import java.awt.FlowLayout;import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;public class Test_6 extends JFrame { Box b1,b2,b3;
public Test_6() {
setBounds(100, 100, 300, 200);
setLayout(new FlowLayout());
b1=Box.createVerticalBox();
b1.add(new JLabel("姓名"));
b1.add(Box.createVerticalStrut(10));
b1.add(new JLabel("email"));
b2=Box.createVerticalBox();
b2.add(new JTextField(10));
b2.add(Box.createVerticalStrut(10));
b2.add(new JTextField(10));
b3=Box.createHorizontalBox();
b3.add(b1);
b3.add(Box.createHorizontalStrut(8));
b3.add(b2);
add(b3);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public static void main(String[] args) {
new Test_6(); }}

㈢ java中box属于哪个类

是这个吗?

㈣ JAVA中 box.createVerticalStrut()是什么意思

请问下box是什么类啊!说出来我帮你查!要么我把api传给你吧

㈤ java中box类有何作用具体点哦

public class Box extends JComponent implements Accessible
使用 BoxLayout 对象作为其布局管理器的一个轻量级容器。
Box 提供几个对使用 BoxLayout 的容器(甚至非 Box 容器)有用的类方法。

Box 类可以创建几种影响布局的不可见组件:glue、struts 和 rigid 区域。如果 Box 包含的所有组件都有一个固定大小,可以使用 glue 组件(由 createGlue 返回)来控制组件的位置。如果想让两个组件之间有一个固定的空间量,可以尝试使用 strut(createHorizontalStrut 或 createVerticalStrut)。如果需要一个总是占用相同空间量的不可见组件,可以通过调用 createRigidArea 获得。

想要学好JAVA,在牢固掌握基础的条件下,多做练习.
按我老师的话说,少睡会觉,多背背JDK文档里的类.

㈥ java box怎么用谁能形象的解释一下Box的用法

Box一般用的最多的就是
Box createHorizontalBox() <1>
Box createVerticalBox() <2>
Component createHorizontalStrut(int width) <3>
Component createVerticalStrut(int height) <4>
Component createHorizontalGlue() <5>
Component createVerticalGlue() <6>
Box用的是BoxLayout布局,
其中<1><2>连用可以完成一些盒式布局,最常见的就是登陆/注册界面了。
其中<3><4><5><6>都是一些不可见的组件,辅助支持组件布局,能使界面较美观。

顺便给一个例子:

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
public class Example10_5{
public static void main(String args[]){
new WindowBox();
}
}
class WindowBox extends JFrame{
Box baseBox,boxV1,boxV2;
WindowBox(){
boxV1=Box.createVerticalBox();
boxV1.add(new JLabel("输入您的姓名"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new JLabel("输入email"));
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(new JLabel("输入您的职业"));
boxV2=Box.createVerticalBox();
boxV2.add(new JTextField(16));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(16));
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(new JTextField(16));
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(10));
baseBox.add(boxV2);
setLayout(new FlowLayout());
add(baseBox);
validate();
setBounds(120,125,200,200);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}

㈦ java中的Box类是什么 ,比如图中三行代码的作用是什么,Box.createVerticalBox()又是什么意思

Box是一个布局类,在GUI程序设计时用到的。
Box对象通常不采用构造方法生成,而是用类的静态方法生成,比如上例,产生3个垂直布局的Box对象。

㈧ swing里的box是什么作用java

主要就用到了这四个方法
createHorizontalBox()
创建一个从左到右显示其组件的 Box。
createHorizontalStrut(int width) //左右部件之间的中间间隔就可以用这个方法来控制
创建一个不可见的、固定宽度的组件。
createVerticalBox()
创建一个从上到下显示其组件的 Box。
createVerticalStrut(int height) //上下部件之间的中间间隔就可以用这个方法来控制
创建一个不可见的、固定高度的组件。

效果图如下
package com.geogro.webapp.applet.track;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

/**3G版本的数据过滤面板,输入过滤值查询3G值.
*
* @author snail
* @date 07-03-26
* @version 1.0
*/
public class Fliter3GPanel extends JPanel {
private static Font defaultFont = new Font("SimSun", Font.PLAIN, 12); //默认字体
TitledBorder titledBorder1 = new TitledBorder("参数设置");
JTextField xTextField;
JTextField yTextField;
JTextField zTextField;
JTextField inteTextField;
DateChooserJButton fliterStartTimeButton;
DateChooserJButton fliterEndTimeButton;
JProgressBar fliterLoadBar;
JButton okButton;
JButton cancelButton;

private void jbInit() throws Exception {
Box b = Box.createVerticalBox();
JLabel bannerLabel = new JLabel("3G数据过滤查询");
b.add(bannerLabel);

//-------------setTheInputPanel------------------------------

JPanel inputPanel = new JPanel();
TitledBorder inputPanelBorder = new TitledBorder("设置参数");
inputPanelBorder.setTitleFont(defaultFont);
inputPanel.setBorder(inputPanelBorder);

Box vtemp = Box.createVerticalBox();
Box htemp1 = Box.createHorizontalBox();
Box htemp2 = Box.createHorizontalBox();
Box htemp3 = Box.createHorizontalBox();
Box htemp4 = Box.createHorizontalBox();
Box htemp5 = Box.createHorizontalBox();
Box htemp6 = Box.createHorizontalBox();
Box htemp7 = Box.createHorizontalBox();
Box htemp8 = Box.createHorizontalBox();

xTextField = new JTextField();
xTextField.setPreferredSize(new Dimension(50, 10));
htemp1.add(new JLabel("横向:"));
htemp1.add(Box.createHorizontalStrut(10)); //创建label和textFied之间的距离
htemp1.add(xTextField);
htemp1.add(new JLabel("(例:3.01)"));

yTextField = new JTextField();
yTextField.setPreferredSize(new Dimension(50, 10));
htemp2.add(new JLabel("纵向:"));
htemp2.add(Box.createHorizontalStrut(10));
htemp2.add(yTextField);
htemp2.add(new JLabel("(例:4.01)"));

zTextField = new JTextField();
zTextField.setPreferredSize(new Dimension(50, 10));
htemp3.add(new JLabel("垂直:"));
htemp3.add(Box.createHorizontalStrut(10));
htemp3.add(zTextField);
htemp3.add(new JLabel("(例:3.01)"));

inteTextField = new JTextField();
inteTextField.setPreferredSize(new Dimension(50, 10));
htemp4.add(new JLabel("综合:"));
htemp4.add(Box.createHorizontalStrut(10));
htemp4.add(inteTextField);
htemp4.add(new JLabel("(例:5.01)"));

fliterStartTimeButton = new DateChooserJButton();
JLabel tmpLabel = new JLabel("开始时间:");
htemp5.add(tmpLabel);
htemp5.add(fliterStartTimeButton);

fliterEndTimeButton = new DateChooserJButton();
JLabel tmpLabel2 = new JLabel("结束时间:");
htemp6.add(tmpLabel2);
htemp6.add(fliterEndTimeButton);

fliterLoadBar = new JProgressBar();
JLabel tmpLabel3 = new JLabel("进度:");
htemp7.add(tmpLabel3);
htemp7.add(fliterLoadBar);

okButton = new JButton("过滤");
cancelButton = new JButton("撤销");
htemp8.add(okButton);
htemp8.add(Box.createHorizontalStrut(10));
htemp8.add(cancelButton);

vtemp.add(htemp1);
vtemp.add(Box.createVerticalStrut(10)); //创建上下空间距离
vtemp.add(htemp2);
vtemp.add(Box.createVerticalStrut(10));
vtemp.add(htemp3);
vtemp.add(Box.createVerticalStrut(10));
vtemp.add(htemp4);
vtemp.add(Box.createVerticalStrut(10));
vtemp.add(htemp5);
vtemp.add(Box.createVerticalStrut(10));
vtemp.add(htemp6);
vtemp.add(Box.createVerticalStrut(25));
vtemp.add(htemp7);
vtemp.add(Box.createVerticalStrut(5));
vtemp.add(htemp8);

inputPanel.add(vtemp);
//----------------------------------------------------------

//------------other panel init here-------------------------

//initCode!

//----------------------------------------------------------

b.add(inputPanel);
//b.add(otherPanel);

this.add(b, BorderLayout.NORTH);
}

public Fliter3GPanel() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}

}

㈨ java中的BOX 是什么意思

自己查查API 就知道了