JScrollPane not working in null layout

后端 未结 2 1164
野趣味
野趣味 2021-01-27 23:26
  import javax.swing.JCheckBox;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;

public class Sc         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 00:25

    You should create your own panel that extends JPanel containing all checkboxes and in this panel override getPreferredSize() method like:

    @Override
    public Dimension getPreferredSize()
    {
        return new Dimension( 300,300 );
    }
    

    and use it in your code:

    ...
    
    // creating the scroll pane that will scroll the panel.
    JScrollPane jscrlPane = new JScrollPane( new MyPanelWithCheckboxes() );
    jscrlPane.setBounds( 0, 0, 300, 300 );
    ...
    

提交回复
热议问题