JScrollPane 添加到流式布局的有多个JButton的JPanel上,如何使水平拉伸保持流式布局特点,垂直加滚动条? 15
publicclasstest{publicstaticvoidmain(String[]args){JPaneljp=newJPanel();jp.setLayout(...
public class test {
public static void main(String[] args) {
JPanel jp = new JPanel ();
jp.setLayout(new FlowLayout());
JButton[] jbt = new JButton[100];
JScrollPane jsp = new JScrollPane(jp);
JFrame jf = new JFrame();
for(int i = 0 ; i<100 ;i++){
jbt[i] = new JButton("OK");
jbt[i].setPreferredSize(new Dimension(150, 150));
jp.add(jbt[i]);
}
jf.add(jsp);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(848, 480);
jf.setLocationRelativeTo(null);
}
} 展开
public static void main(String[] args) {
JPanel jp = new JPanel ();
jp.setLayout(new FlowLayout());
JButton[] jbt = new JButton[100];
JScrollPane jsp = new JScrollPane(jp);
JFrame jf = new JFrame();
for(int i = 0 ; i<100 ;i++){
jbt[i] = new JButton("OK");
jbt[i].setPreferredSize(new Dimension(150, 150));
jp.add(jbt[i]);
}
jf.add(jsp);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(848, 480);
jf.setLocationRelativeTo(null);
}
} 展开
1个回答
展开全部
JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
Creates a JScrollPane that displays the view component in a viewport whose view position can be controlled with a pair of scrollbars.
VERTICAL_SCROLLBAR_NEVER,HORIZONTAL_SCROLLBAR_AS_NEEDED
或者
voidsetHorizontalScrollBarPolicy(int policy)
Determines when the horizontal scrollbar appears in the scrollpane.
void setVerticalScrollBarPolicy(int policy)
Determines when the vertical scrollbar appears in the scrollpane.
Creates a JScrollPane that displays the view component in a viewport whose view position can be controlled with a pair of scrollbars.
VERTICAL_SCROLLBAR_NEVER,HORIZONTAL_SCROLLBAR_AS_NEEDED
或者
voidsetHorizontalScrollBarPolicy(int policy)
Determines when the horizontal scrollbar appears in the scrollpane.
void setVerticalScrollBarPolicy(int policy)
Determines when the vertical scrollbar appears in the scrollpane.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询