我使用的是JBuilder2006.做了个类,继承JPanel,上面有一些控件(JLabel,JText,JButton...)。然后再在另一个窗体的内容面板new 出几个来,如果那个窗体是流式布局的话,就什么也不显示,但如果是网格布局的话,能出来,但是new 一个两个还好,我如果要new 很多的话,就不行了,加滚动面板也不行,我希望能有滚动条,而且是流式布局那样,不论new 多少都行,怎么解决? 在线等,谢谢了
调试欢乐多
我也是新手
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();}
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);
jPanel1.add(panel1);
jPanel1.add(panel2);
} public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.setVisible(true);
} 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();
Panel1 panel1=new Panel1();
Panel1 panel2=new Panel1();}
如我自己做的一个子界面package com.hydrology.form;import javax.swing.*;
import java.awt.Rectangle;public class Panel1 extends JPanel
{
public Panel1()
{
try
{
jbInit();
} catch (Exception ex)
{
ex.printStackTrace();
} } private void jbInit() throws Exception
{
this.setLayout(null);
jButton1.setBounds(new Rectangle(73, 72, 117, 59));
jButton1.setText("jButton1");
jToggleButton1.setText("jToggleButton1");
jToggleButton1.setBounds(new Rectangle(73, 174, 157, 57));
this.add(jButton1);
this.add(jToggleButton1);
} JButton jButton1 = new JButton();
JToggleButton jToggleButton1 = new JToggleButton();}
setSize(300,300);//数字自己根据你自己需要修改
setVisible(true);