Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add JScrollPane in a JList ?

 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




I want to add JScrollPane in the Jlist ? How can I do ?Thank you !
 
Paul Clapham
Sheriff
Pie
Posts: 20775
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... then does that mean you want one of the entries in the list to be a JScrollPane, instead of the usual JLabel? Or do you want all of them to be a JScrollPane? The code you posted doesn't say anything about that. (In fact it really doesn't tell me anything except that you are using a JList.)

Anyway, here's a link to the JList tutorial. It has a section about how to use custom renderers, which is the official answer to your question. It just seems like a really strange UI design to me. Did you really mean to ask that?
 
Song Guo
Greenhorn
Posts: 24
Chrome Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Okay... then does that mean you want one of the entries in the list to be a JScrollPane, instead of the usual JLabel? Or do you want all of them to be a JScrollPane? The code you posted doesn't say anything about that. (In fact it really doesn't tell me anything except that you are using a JList.)

Anyway, here's a link to the JList tutorial. It has a section about how to use custom renderers, which is the official answer to your question. It just seems like a really strange UI design to me. Did you really mean to ask that?


Thank you ! The code I posted creates a JList,but if the items it contains are many,some items cannot display.So I want to add a JScrollPane,for instances:(attachments)

Look forward to your reply.
截图1303707718.jpg
instance
[Thumbnail for 截图1303707718.jpg]
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the link Paul provided? It shows how to wrap the JList in a JScrollPane.
1) Create JList
2) Create JScrollPane
3) Add JList to JScrollPane
4) Add the JScrollPane to the parent container

Some pointers


Why are you having a separate method for this? You can always add directly to the default content pane.


Any particular reason for a null layout? It is always a good idea to a proper LayoutManager
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic