Results 1 to 4 of 4
  1. #1
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default pack() method for JButton?

    Is there anything in the JButton class that acts like JFrame's pack() method? I'm looking for something that does two things:

    1) automatically sizes the button to fit its text snugly and doesn't crop it.

    2) minimizes the overall size of the button so that the text is still fully visible (i.e. not cropped) yet no space surrounding the text is wasted.

    I know I can use setPreferredSize(Dimension) to do this, but that requires a bit of trial and error before you get it right. I'm wondering if there's an alternative that gets it right the first time.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default

    Doesn't the default get it right the first time?

    What Layout are you using?

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

    Default

    Agree, your issue is likely a layout issue. Often the key is to nest containers, often JPanels each using its own layout.

  4. #4
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default

    Well, I took out all my button.setPreferredSize() method calls and it seems to work now. It's a bit confusing though since I had those setPreferredSize() calls in there because of problems with sizing the buttons properly to begin with. Now I don't have that problem for some reason. Go figure.

    Thanks for the help.

Similar Threads

  1. pack libraries into jar file
    By BigBear in forum New To Java
    Replies: 1
    Last Post: 05-24-2010, 11:19 AM
  2. Get item from string array and pack with blank space
    By firewalll in forum New To Java
    Replies: 2
    Last Post: 09-02-2009, 07:38 AM
  3. Replies: 0
    Last Post: 03-26-2009, 04:07 PM
  4. Replies: 0
    Last Post: 09-30-2008, 10:06 AM
  5. visual web pack
    By Jack in forum NetBeans
    Replies: 2
    Last Post: 07-02-2007, 05:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •