Reputation: 309
I have added a scroll pane to the main panel of my frame. But it doesn't display properly, here's what I get that appears on the right:
http://postimage.org/image/extp3ncql/
here is the code:
JScrollPane jScrollPane = new JScrollPane(area);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane.setViewportBorder(new LineBorder(Color.RED));
pane.add(jScrollPane, BorderLayout.EAST);
EDIT: Forgot to mention that area is a label.
Upvotes: 0
Views: 189
Reputation: 109813
1) Use another proper LayoutManager
, I'd suggesst use Box
or directly BoxLayout
or
2) all areas excluding BorderLayout.CENTER
acepted PreferredSize
came from JComponent
3) if your area
is JTextArea the you can pretty to set JTextArea(int rows, int columns)
Upvotes: 3