aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to add JScrollPane in a JList ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add JScrollPane in a JList ?" Watch "How to add JScrollPane in a JList ?" New topic
Author

How to add JScrollPane in a JList ?

Song Guo
Greenhorn

Joined: Apr 24, 2011
Posts: 24





I want to add JScrollPane in the Jlist ? How can I do ?Thank you !
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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

Joined: Apr 24, 2011
Posts: 24

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.



[Thumbnail for 截图1303707718.jpg]

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

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

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add JScrollPane in a JList ?