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

    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?

    Thanks!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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
    Posts
    3
    Rep Power
    0

Similar Threads

  1. padding informaiton for PKCS#5
    By nanaji in forum Advanced Java
    Replies: 3
    Last Post: 07-31-2008, 06: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, 05: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, 05: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
  •