Results 1 to 3 of 3
  1. #1
    subb is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default Single Component Padding

    Hi Everyone,

    I'm learning Java this semester at school and I'm trying to build a simple component. Basically it's a numeric label that, when clicked, switch to a textfield to let you modify the value, or if you "click-drag" the label, you can "scroll" the value like a slider.

    I've set up a textfield and a label in a JPanel with a CardLayout. Works perfectly, except for one thing...

    The label component always takes the maximum space available in the JPanel. That means even if the label's text is short, it's possible to click anywhere on the label to "click-drag" it, which I don't want. I want the user to click only on the actual text, or in other words, I want the label to have the same width as its text.

    How can I do that?


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Place the label into a JPanel that uses FlowLayout(FlowLayout.CENTER) if you want it centered. Then place that JPanel into the CardLayout using container.

  3. #3
    subb is offline Member
    Join Date
    Mar 2009
    Rep Power

Similar Threads

  1. padding informaiton for PKCS#5
    By nanaji in forum Advanced Java
    Replies: 3
    Last Post: 07-31-2008, 05:36 AM
  2. Creating a tabbed display with a single tab
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:44 PM
  3. Compiling a single class
    By ROSOBORONEXPORTCORP in forum New To Java
    Replies: 2
    Last Post: 01-28-2008, 01:27 PM
  4. convert a lot of images into a single one
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:47 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