Advice needed for adding a JScrollPane to JPanel


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Advice needed for adding a JScrollPane to JPanel

  1. #1
    Join Date
    May 2005
    Posts
    75

    Advice needed for adding a JScrollPane to JPanel

    What I've done is added a JScrollPane to a JPanel and everything worked fine until I changed the JPanel's layout from GridLayout to null. I am adding a lot of JButtons to this panel and changed the layout to null so I have more control over how the buttons look. The problem is that now the JPanel doesn't scroll. The scrollbars are there but they do nothing.

    To summarize: How do I had a JScrollPane to a JPanel who's layout is null?

    secondary question: If a JButton thinks there isn't enough room to display it's label, is it possible to force it to paint it anyway instead of '...'?

    Thanks!

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    you mean you added a panel to a scrollpane? you'd have to override the preferredSize method of the panel and calculate the size you want manually. No layout, it doesn't know how big to make the component. So it'll default to the size of the space its given. Scrollpane only kicks in basically when that component extends beyond visible bounds.

  3. #3
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    setting layout to null will generate problems, since the jscrollpane will not know, how big the underlying pane is.
    if you want to control the positions of your components by yourself, you will have to write your own layoutmanager, that will calculate its preffered size by wvaluation position and size information of included components.
    Instead use the absolutepositioninglayoutmanager provided at my blog:
    http://narcanti.keyboardsamurais.de/...es-layout.html
    it allows you to set the components wherever you want, and calculates correct sizes for min and preferred size.

Similar Threads

  1. Replies: 2
    Last Post: 03-22-2006, 03:10 AM
  2. JPanel paintComponent inside JScrollPane
    By vu_tech in forum Java
    Replies: 1
    Last Post: 04-08-2005, 10:36 AM
  3. ASP program architectures -- advice needed
    By Dan Newman in forum ASP.NET
    Replies: 0
    Last Post: 12-12-2001, 05:20 PM
  4. JAVA help
    By Munchkin in forum Java
    Replies: 3
    Last Post: 03-16-2001, 04:58 PM
  5. Replies: 1
    Last Post: 05-08-2000, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center