日期:2014-05-20  浏览次数:20638 次

做JAVA界面的问题?
我使用的是JBuilder2006.

做了个类,继承JPanel,上面有一些控件(JLabel,JText,JButton...)。然后再在另一个窗体的内容面板new   出几个来,如果那个窗体是流式布局的话,就什么也不显示,但如果是网格布局的话,能出来,但是new   一个两个还好,我如果要new   很多的话,就不行了,加滚动面板也不行,我希望能有滚动条,而且是流式布局那样,不论new   多少都行,怎么解决?   在线等,谢谢了

------解决方案--------------------
我想是不是应该在窗体中用pack()函数,这样会不会就不用滚动条了.


我也是新手
------解决方案--------------------
package utilbeans;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import javax.swing.JPanel;

/**
* <p> Title: </p>
*
* <p> Description: </p>
*
* <p> Copyright: Copyright (c) 2007 </p>
*
* <p> Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
public Frame1() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

private void jbInit() throws Exception {
getContentPane().setLayout(null);
jScrollPane1.setBounds(new Rectangle(4, 7, 522, 494));
this.getContentPane().add(jScrollPane1);
jButton1.setText( "jButton1 ");
jPanel1.setLayout(flowLayout1);
jScrollPane1.getViewport().add(jPanel1);
jButton2.setText( "jButton2 ");
jButton3.setText( "jButton3 ");
jButton4.setText( "jButton4 ");
jButton5.setText( "jButton5 ");
jButton6.setText( "jButton6 ");
jButton7.setText( "jButton7 ");
jButton8.setText( "jButton8 ");
jButton9.setText( "jButton9 ");
jButton10.setText( "jButton10 ");
jPanel1.add(jButton1);
jPanel1.add(jButton2);
jPanel1.add(jButton3);
jPanel1.add(jButton4);
jPanel1.add(jButton5);
jPanel1.add(jButton6);
jPanel1.add(jButton7);
jPanel1.add(jButton8);
jPanel1.add(jButton9);
jPanel1.add(jButton10);

}

public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.show();
}

JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
JButton jButton7 = new JButton();
JButton jButton8 = new JButton();
JButton jButton9 = new JButton();
JButton jButton10 = new JButton();

}


------解决方案--------------------
好帖 顶 学习
------解决方案--------------------
有点不知所云的感觉, 请楼主先整理一个思路, 然后用更清晰的语言表达出来.
------解决方案--------------------
对呀,感觉楼主表达的不是很清楚呀,不知道你要问什么呀.
------解决方案--------------------
jbInit() 函数里面底部添加以下几句再试试看能不能显示。
setSize(300,300);//数字自己根据你自己需要修改