I have a JPanel
with a layout CardLayout
and in every card there is another JPanel
with a layout BorderLayout
which has a JScrollPane
inside.
ie.
JScrollPane jscrollPane = new JScrollPane(filter.getFilterComponent());
JPanel jPanel = new JPanel(new CardLayout());
jPanel.add(jscrollPane);
JPanel container = new JPanel(new BorderLayout());
container.add(jPanel, BorderLayout.CENTER );
filter.getFilterComponent()
can be textbox, list of checkboxes or etc.
The problem is when it is a JTextField
it look like this
which is undesirable behavior. When I use FlowLayout
, no matter how tall the component is the scroll bar doesn't appear. I think its because its parent container preferredSize
is 0
How can I prevent the component inside the JScrollPane
from re sizing and keep its dimension to its original? Or there is another way of doing this?