Add a JScrollPane to a JLabel
Solution 1
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
Solution 2
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!
Solution 3
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
Soler Mani
Updated on June 05, 2022Comments
-
Soler Mani almost 2 years
I can't seem to find out how I can add a
JScrollPane
to aJLabel
. TheJLabel
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);