• Post Reply Bookmark Topic Watch Topic
  • New Topic

Label not displaying when wrapped in JScrollPane  RSS feed

 
Gary Fletcher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to display a JComboBox and a JLabel on the same JPanel.

When wrapping the JLabel in a JScrollPane it does not display, however when not wrapped the JLabel does display. I have tried evrything I know, which isn't a lot at the moment but with no success. Coould someone take a look an explain what I am doing wrong.

Thanks

main


ComboFrame


ComboPanel


ComboLabel


LabelScroll


ComboCombo
 
Andrea Binello
Ranch Hand
Posts: 47
4
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gary Fletcher wrote:

First of all, extending JScrollPane is one of those things that rarely are done. That is, normally JScrollPane is simply instantiated and used directly.

However, by itself, this is not the problem. The problem is that you have used add. JScrollPane is a very specific component. It's not a generic container. So you should not use add.

Use setViewportView(cl); or since you are in the constructor, invoke super(cl); (invoking the constructor of JScrollPane that receives the "view" component to scroll).
 
Gary Fletcher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrea. That worked brilliantly.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!