Closed Thread
Results 1 to 8 of 8

Thread: change JButton size

  1. #1
    stack is offline Learning Programmer
    Join Date
    Mar 2007
    Posts
    42
    Rep Power
    0

    Question change JButton size

    hi,
    how can i change the size of JButton ( i want the size of JButton to be 25X25)...
    i used setPreferredSize(Dimension d) method but it didn't work with me??!!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,264
    Blog Entries
    26
    Rep Power
    20
    [HIGHLIGHT="Java"]setPreferredSize(new Dimension(25, 25))[/HIGHLIGHT]

    Will work unless you have a layout manager that overrides manual changes, and there may be other reasons, but of course I can not say for sure because you give no example of your code.

  4. #3
    Howdy_McGee is offline Programmer
    Join Date
    May 2010
    Posts
    133
    Rep Power
    7

    Re: change JButton size

    Sorry for bringing this thread back from the dead but I had a question regarding the topic.

    setPreferredSize will work but JButtons, but not if I have a setLayout(GridLayout) right?

  5. #4
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,889
    Rep Power
    25

    Re: change JButton size

    Nope, the gridlayout gives all components inside it the same width / height.

    A boxLayout puts all components in a SINGLE row or column without affecting them. (BoxLayout)
    Now because it's much likely you want multiple rows or columns i suggest you try to put panels in a gridLayout and the panels set up with a boxLayout
    Like this if you know what i mean:
    Code:
    -------------GRIDLAYOUT--------------
    |   B   |   B     |   B    |   B   |
    |   O   |   O     |   O    |   O   |
    |   X   |   X     |   X    |   X   |
    |       |         |        |       |
    |       |         |        |       |
    -------------------------------------

  6. #5
    Howdy_McGee is offline Programmer
    Join Date
    May 2010
    Posts
    133
    Rep Power
    7

    Re: change JButton size

    Nvm I found out, John was right, this worked:

    ButtName.setPreferredSize(new Dimension(buttonWidth, buttonHeight));

  7. #6
    organizedchaos's Avatar
    organizedchaos is offline Learning Programmer
    Join Date
    Jun 2009
    Posts
    38
    Rep Power
    0

    Re: change JButton size

    I'm also having this problem. I used this code:
    Code:
    ButtName.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
    but I'm getting this error:
    Code:
    cannot find symbol
    symbol  : class Dimension
    How do I declare or instantiate "Dimension"?

    Thanks!

  8. #7
    Join Date
    May 2009
    Location
    Belgium
    Posts
    1,889
    Rep Power
    25

    Re: change JButton size

    Try to import
    Code:
    java.awt.Dimension;
    OR
    java.awt.*;

  9. #8
    organizedchaos's Avatar
    organizedchaos is offline Learning Programmer
    Join Date
    Jun 2009
    Posts
    38
    Rep Power
    0

    Re: change JButton size

    wow! That worked! Thanks!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 guests)

Similar Threads

  1. JButton Help
    By dkwb in forum Java Help
    Replies: 7
    Last Post: 08-01-2011, 10:07 AM
  2. J2EE: Limit File Size or Request Size
    By tarek.mostafa in forum Java Help
    Replies: 0
    Last Post: 05-27-2010, 05:46 AM
  3. Change font size of 'Product', 'Size', ...
    By DavidBoggitt in forum ionFiles
    Replies: 1
    Last Post: 09-03-2009, 06:21 PM
  4. Size/Size on Disk
    By BlaineSch in forum Technology Ramble
    Replies: 14
    Last Post: 07-03-2009, 05:44 AM
  5. Change Resolution, Change Size
    By Void in forum C# Programming
    Replies: 1
    Last Post: 06-13-2006, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

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