JScrollPane滚动条组件,注意你想添加一个组件到里面,下面的方法不行:

JTextArea jta=new JTextArea();
JScrollPane jsp=new JScrollPane();
jsp.add(jta);

jta是不会显示的。这个很特殊,有2中方法向JScrollPane添加组件:

1.在构造方法中把要添加的组件传进去。

JTextArea jta=new JTextArea();
JScrollPane jsp=new JScrollPane(jta);

 

2.使用 scrollPane.getViewport().add(label) 形式:

public class Notepad extends JFrame {
        ...
      private JMenuItem newMenu = new JMenuItem("New");
    private JScrollPane scrollPane = new JScrollPane();

        ...
        setTitle("MDI Test");
          scrollPane.getViewport().add(desktop);
       getContentPane().setLayout(new BorderLayout());

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-09-15
  • 2018-03-10
  • 2021-06-08
  • 2022-12-23
猜你喜欢
  • 2021-05-31
  • 2019-12-05
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
相关资源
相似解决方案