java面板中设置gridlayout怎么使用JScrollPane才能显示出来 5
publicclassMidaPlayerKnoledgeextendsJFrame{publicMidaPlayerKnoledge(){super("TestJScr...
public class MidaPlayerKnoledge extends JFrame {
public MidaPlayerKnoledge() {
super("TestJScrollPane");
this.setLayout(new GridLayout(2,1));
this.setBounds(200, 200, 300, 300);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(200,100));
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setBounds(10, 10, 175, 70);
JPanel panel1= new JPanel();
this.getContentPane().add(scrollPane);
this.getContentPane().add(panel1);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MidaPlayerKnoledge();
}
} 展开
public MidaPlayerKnoledge() {
super("TestJScrollPane");
this.setLayout(new GridLayout(2,1));
this.setBounds(200, 200, 300, 300);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(200,100));
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setBounds(10, 10, 175, 70);
JPanel panel1= new JPanel();
this.getContentPane().add(scrollPane);
this.getContentPane().add(panel1);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MidaPlayerKnoledge();
}
} 展开
1个回答
展开全部
lz 你好
给你一个简单的例子吧
import java.awt.*;
import javax.swing.*;
public class MidaPlayerKnoledge extends JFrame {
public MidaPlayerKnoledge() {
super("TestJScrollPane");
this.setLayout(new GridLayout(2,1));
this.setBounds(200, 200, 300, 300);
JPanel panel = new JPanel(new GridLayout(20,5));
//加一些标签 就能显示了
JLabel[] num = new JLabel[100];
for (int i = 0; i < num.length; i++) {
num[i] = new JLabel("迅樱"+(i+1));
panel.add(num[i]);
}
轿芹 //panel.setPreferredSize(new Dimension(200,100));
//这段代码去掉 否则会乱码 在GridLayout下不能设置组件的大小
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setBounds(10, 10, 175, 70);
JPanel panel1= new JPanel();
this.getContentPane().add(scrollPane);
this.getContentPane().add(panel1);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] 闭昌毕args) {
new MidaPlayerKnoledge();
}
}
希望能帮助你哈
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询