Jump to content




Recent Status Updates

  • Photo
      26 Jul
    Kadence

    It's been so long since I've coded I actually don't feel like the same person anymore.

    Show comments (2)
View All Updates

Binpress - Cut your development time and costs in half
Photo
- - - - -

change JButton size

jbutton setpreferredsize

  • Please log in to reply
7 replies to this topic

#1 stack

stack

    CC Regular

  • Just Joined
  • PipPipPip
  • 42 posts

Posted 15 September 2007 - 05:25 AM

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??!!
  • 1

#2 John

John

    CC Mentor

  • Moderator
  • 4,450 posts
  • Location:New York, NY

Posted 15 September 2007 - 01:23 PM

setPreferredSize(new Dimension(25, 25))


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.
  • 0

#3 Howdy_McGee

Howdy_McGee

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 102 posts

Posted 21 May 2010 - 10:17 PM

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?
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,551 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 22 May 2010 - 12:41 AM

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:
-------------GRIDLAYOUT--------------
|   B   |   B     |   B    |   B   |
|   O   |   O     |   O    |   O   |
|   X   |   X     |   X    |   X   |
|       |         |        |       |
|       |         |        |       |
-------------------------------------


  • 0

#5 Howdy_McGee

Howdy_McGee

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 102 posts

Posted 23 May 2010 - 07:27 PM

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

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

#6 organizedchaos

organizedchaos

    CC Regular

  • Just Joined
  • PipPipPip
  • 32 posts

Posted 02 August 2010 - 11:21 PM

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

Thanks!
  • 0

#7 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2,551 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java, PHP

Posted 03 August 2010 - 01:53 AM

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

  • 0

#8 organizedchaos

organizedchaos

    CC Regular

  • Just Joined
  • PipPipPip
  • 32 posts

Posted 03 August 2010 - 04:16 AM

wow! That worked! Thanks!
  • 0





Also tagged with one or more of these keywords: jbutton, setpreferredsize

Powered by binpress