Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to set p's preferredSize for this to work.</p> <pre><code> p.setPreferredSize(new Dimension(800, 2000)); </code></pre> <p>Or you could have p extend JPanel and then override the getPreferredSize() method to return the proper dimension.</p> <p>And I agree -- get rid of your null layouts. Learn about and use the layout managers if you want to use Swing correctly and have robust Swing GUI's.</p> <p>e.g.,</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Foo extends JFrame { private static final int BUTTON_COUNT = 25; public static void main(String[] args) { JPanel btnPanel = new JPanel(new GridLayout(0, 1, 0, 20)); btnPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); AbstractAction removeAction = new AbstractAction("Remove") { @Override public void actionPerformed(ActionEvent evt) { JButton src = (JButton) evt.getSource(); JPanel container = (JPanel) src.getParent(); container.remove(src); container.revalidate(); container.repaint(); } }; for (int i = 0; i &lt; BUTTON_COUNT; i++) { JButton removeBtn = new JButton(removeAction); btnPanel.add(removeBtn); } JPanel borderPanel = new JPanel(new BorderLayout()); borderPanel.add(btnPanel, BorderLayout.NORTH); JScrollPane scrollpane = new JScrollPane(borderPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollpane.setPreferredSize(new Dimension(400, 800)); JFrame frame = new JFrame("Foo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(scrollpane); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload