• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add JScrollPane in a JList ?

 
Greenhorn
Posts: 24
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I want to add JScrollPane in the Jlist ? How can I do ?Thank you !
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for -1303707718.jpg]
instance
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic