import javax.swing.*;
import java.awt.*;public class TestFlowLayout
extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
BorderLayout borderLayout1 = new BorderLayout(); public TestFlowLayout() {
try {
this.setSize(400, 300);
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.LEFT);
for (int i = 9; i < 69; i++) {
jPanel1.add(new JButton("JButton" + (i + 1)), null);
}
jPanel1.setPreferredSize(new Dimension(380, -1));
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jPanel1, null);
} public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
TestFlowLayout frame = new TestFlowLayout();
frame.setVisible(true);
}}
import java.awt.*;public class TestFlowLayout
extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
BorderLayout borderLayout1 = new BorderLayout(); public TestFlowLayout() {
try {
this.setSize(400, 300);
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(borderLayout1);
jPanel1.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.LEFT);
for (int i = 9; i < 69; i++) {
jPanel1.add(new JButton("JButton" + (i + 1)), null);
}
jPanel1.setPreferredSize(new Dimension(380, -1));
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jPanel1, null);
} public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
e.printStackTrace();
}
TestFlowLayout frame = new TestFlowLayout();
frame.setVisible(true);
}}
解决方案 »
- 一个有关java Boolean的小问题请高手帮忙解答
- 竞赛题目、求牛人解答、
- java BigInteger范围
- java 如何实现自定义事件的触发及监听?
- applet初学者小问题,竟然没人帮我.好郁闷啊............................
- 一道书上的练习,求答案
- !!!怎么样可以让java建立的socket可以收到局域网发来的任何数据??!!!!!!!!!!!!!
- 如何用java程序实现无限循环但每隔5秒检测键盘输入,若为q退出循环和程序的程序??
- 如何用最简单的方法去掉一个String中的"\n"和"\r"?急急急……(在线等待)
- 新手问题之五:JAVA中怎样调用WINDOWS的DLL中的函数?
- java里有没有像QQ那样实现“我的好友”,“通讯录”, “群/校友录”,“最近联系人”,点一下按钮弹到最上面,并且在其栏下有很多图片按
- 求以中文词结尾的正则表达式
改为jPanel1.setPreferredSize(new Dimension(380, 380));就OK了
jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);纵向的滚动条是有了,但不能滚动。jPanel1的内容也还是看不到。to:hemiao_1993(冷血动物)
jPanel1.setPreferredSize(new Dimension(380, 380));后是能滚动了,但jPanel1的内容是动态的,这样好象不行的。总之还是要谢谢二位。
this.setSize(400, 300);
上面这句设置了300
下面的话不能小于265,低于这个数字好象就不行了.