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 就知道了