• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to add JScrollPane in a JList ?

 
Greenhorn
Posts: 24
Redhat Chrome Java
  • 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 !
 
Marshal
Posts: 26282
80
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
Redhat Chrome Java
  • 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
[Thumbnail for -1303707718.jpg]
instance
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic