| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 816 人关注过本帖
标题:[求助]布局问题
只看楼主 加入收藏
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
 问题点数:0 回复次数:2 
[求助]布局问题

import java.awt.GridBagLayout;
import java.awt.Panel;
import javax.swing.BoxLayout;
import java.awt.ComponentOrientation;
import java.awt.SystemColor;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.*;

public class BoxLayoutDemo extends Panel {

private static final long serialVersionUID = 1L;
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JButton jButton3 = null;
private JButton jButton4 = null;
/**
* This is the default constructor
*/
public BoxLayoutDemo() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(426, 200);
this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
this.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
this.setFont(new Font("Dialog", Font.PLAIN, 12));
this.setBackground(SystemColor.activeCaptionBorder);
this.add(getJButton(), null);
this.add(getJButton1(), null);
this.add(getJButton2(), null);
this.add(getJButton3(), null);
this.add(getJButton4(), null);
}

/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("JButton1");
}
return jButton;
}

/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("JButton2");
}
return jButton1;
}

/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("JButton3");
}
return jButton2;
}

/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("JButton4");
}
return jButton3;
}

/**
* This method initializes jButton4
*
* @return javax.swing.JButton
*/
private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setText("JButton5");
}
return jButton4;
}
public static void main(String[] args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch (Exception e ){e.printStackTrace();
}
BoxLayoutDemo frame=new BoxLayoutDemo();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=frame.getSize();
frame.setLocation((screenSize.height-frameSize.height)/2,(screenSize.width-frameSize.width)/2);
frame.setVisible(true);

// @jve:decl-index=0:visual-constraint="68,55"
}
}
程序有什么问题吗?为什么显示不出画面呀?

搜索更多相关主题的帖子: import awt java swing JButton 
2007-08-28 01:55
huwangvs
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:764
专家分:0
注 册:2007-2-4
收藏
得分:0 

Panel不能独立显示的。它相当于画布,你得先把它放到Frame才能显示。
或者直接把组件放到Frame里。

2007-08-28 08:39
xbw0114
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2007-8-8
收藏
得分:0 

哦,这样哦~


勤奋造就未来
2007-08-28 10:51
快速回复:[求助]布局问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069825 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved