how to auto-size JComponents


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: how to auto-size JComponents

  1. #1
    Join Date
    Jun 2004
    Posts
    29

    how to auto-size JComponents

    Hey all,

    I'm sure there's a real easy way to do this so this might sound like a stupid question but... there's got to be a way to get a JComponent to automatically adjust it's width and height such that all its child components are all visible and fit nicely. I need this for both complex components (several levels of subcomponents within it) and simple components (JLabels, JButtons, etc). For the simple components, what I'm looking for is something such that I can call the constructor with an variable sized string, like a JLabel, and have the width automatically set its value so that no "..." appear at the end (ie. the whole string is visible). Any suggestions?

    Gib

  2. #2
    Join Date
    Oct 2002
    Posts
    12
    when you put the components in a frame, call the pack() method

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    sukuri.. you need to use a layout manager for that to work..

    gibby.. see my signature, GridBag tutorial
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

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