Reputation: 309
I can't seem to find out how I can add a JScrollPane
to a JLabel
. The JLabel
that I'm using is populated with a long formatted HTML string. Please help.
area = new JLabel();
JScrollPane scroller = new JScrollPane(area,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
Upvotes: 3
Views: 10519
Reputation: 1258
Can you provide us your code? Are you setting the viewport view to the JLabel
? Instantiate your JLabel
and a JScrollPane
. then set the JScrollPane
viewport to the JLabel (setViewPortView(jlabel);
) then add the JScrollPane
to whatever component you want the scrolling JLabel
to be on.
Hope this helps!
Upvotes: 2
Reputation: 5020
You can't add a JScrollPane
to a JLabel
, what you can do is to create a JScrollPane
and add a JLabel
.
See this: http://www.cs.cf.ac.uk/Dave/HCI/HCI_Handout_CALLER/node63.html
Upvotes: 1
Reputation: 1258
You need to set the JScrollPane
's viewport view:
scroller.setViewPortView(area);
stick that line just before you go panel.add(scroller);
Let us know if that helps or not.
Upvotes: 0
Reputation: 109823
Really not good idea to hold or display long Html formatted text in the JLabel, since is possible, better would be use JEditorPanes / JTextPanes, these JComponets support styled and html formatted text, Icons etc ... , examples for JTextPane and JEditorPane
Upvotes: 7