jpanel放入JScrollPane 高度滚动条不显示
只显示水平,不显示垂直,也设置了setPreferredSize但还是不显示。publicclassPro_DataInputerextendsJFrameimpleme...
只显示水平,不显示垂直,也设置了setPreferredSize但还是不显示。
public class Pro_DataInputer extends JFrame implements ActionListener{
private JPanel jp1;
private JPanel jp2;
private JPanel jp3;
private JLabel jldate;
private JTextField jtdate;
private JScrollPane jsp;
public Pro_DataInputer(ArrayList<Vector> list)
{
this.init();
}
private void init()
{
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jldate = new JLabel("输入日期(格式YYYYMM)");
jtdate = new JTextField();
setSize(600,600);
setLayout(null);
jp1.setBounds(0, 0, 600, 100);
jp2.setPreferredSize(new Dimension(600, 600));
jp3.setBounds(0, 400, 600, 200);
jp3.setSize(600, 150);
jsp = new JScrollPane(jp2);
jsp.getHorizontalScrollBar().setAutoscrolls(false);
jsp.getVerticalScrollBar().setAutoscrolls(true);
jsp.setBounds(0, 100, 600, 300);
getContentPane().add(jsp);
jsp.setViewportView(jp2);
jp1.setLayout(null);
jp1.setBackground(Color.white);
jp2.setBackground(Color.darkGray);
jp3.setBackground(Color.YELLOW);
jldate.setBounds(20, 70, 150, 30);
jtdate.setBounds(170, 70, 130, 30);
jp1.add(jldate);
jp1.add(jtdate);
add(jp1);
add(jsp);
add(jp3);
setLocationRelativeTo(null);
setVisible(true);
}
} 展开
public class Pro_DataInputer extends JFrame implements ActionListener{
private JPanel jp1;
private JPanel jp2;
private JPanel jp3;
private JLabel jldate;
private JTextField jtdate;
private JScrollPane jsp;
public Pro_DataInputer(ArrayList<Vector> list)
{
this.init();
}
private void init()
{
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jldate = new JLabel("输入日期(格式YYYYMM)");
jtdate = new JTextField();
setSize(600,600);
setLayout(null);
jp1.setBounds(0, 0, 600, 100);
jp2.setPreferredSize(new Dimension(600, 600));
jp3.setBounds(0, 400, 600, 200);
jp3.setSize(600, 150);
jsp = new JScrollPane(jp2);
jsp.getHorizontalScrollBar().setAutoscrolls(false);
jsp.getVerticalScrollBar().setAutoscrolls(true);
jsp.setBounds(0, 100, 600, 300);
getContentPane().add(jsp);
jsp.setViewportView(jp2);
jp1.setLayout(null);
jp1.setBackground(Color.white);
jp2.setBackground(Color.darkGray);
jp3.setBackground(Color.YELLOW);
jldate.setBounds(20, 70, 150, 30);
jtdate.setBounds(170, 70, 130, 30);
jp1.add(jldate);
jp1.add(jtdate);
add(jp1);
add(jsp);
add(jp3);
setLocationRelativeTo(null);
setVisible(true);
}
} 展开
2个回答
展开全部
jsp.getHorizontalScrollBar().setAutoscrolls(false);
jsp.getVerticalScrollBar().setAutoscrolls(true);
一个true,一个false
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
布局可以换成BorderLayout
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询