0

I'm trying to create a popup plugin for IntelliJ. The popup contains a JPanel (parentPanel), which contains a JList (I use JBList which is just a sublcass for Intellij) and JTextField. The contents of the list are built dynamically, depending on the contents of the JTextField when the user presses TAB.

This is what I am currently trying. The result is that a new JList is constructed with the proper elements, but the JPanel stays the exact same size, so most of the JList is obstructed. How can I expand the panel (and the whole popup) so that the entire list is visible?

Am I doing something wrong with JPanel, or is the size constrained by the popup itself?

parentPanel receives GridLayout from this line

this.setLayout(new GridLayout(2,1));

Here is the code which modifies the JList.

DefaultListModel listModel = (DefaultListModel) parentPanel.getFileList().getModel();
listModel.removeAllElements();
VirtualFile[] children = currentPathFile.getChildren();

for(int i = 0; i < children.length; ++i) {
   listModel.addElement(children[i].getPath());
}
parentPanel.remove(1); // The list is the panel's second child
parentPanel.add(new JBList(listModel));
parentPanel.revalidate();
parentPanel.repaint();

Even if I give the GridLayout 10 rows, the JList only occupies one row. enter image description here

michaelAdam
  • 1,119
  • 14
  • 30

1 Answers1

1

If parentPanel is a JPanel, its default layout is FlowLayout, which retains the initial preferred size, typically defined by the preferred size of the original content. Try changing it to GridLayout, which will allow the list to grow and shrink as the enclosing panel is resized.

That doesn't work either. GridLayout code has been added.

Because JBList extends JList, you may be able to use setVisibleRowCount(), as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045