Jump to content

JButton

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
Ok I need a JButton to resize and I have tried
button11.setSize(60, 60);
but it isnt working I am using a GridLayout does that keep me from being able to change size?

#2
ksemeks

ksemeks

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
The JButton uses his prefferedSize(). It calculates how much width and height it will need by watching how many characters has to display.
Ex: JButton buttonOne = new JButton("Yes"); JButton buttonTwo = new JButton("This will be a larg ebutton");
In this casse, buttonTwo will be a couple of times bigger than buttonOne, even if you setSize() to both of them.

To resolve this issue, you can change the font name, or you can make another panel in the region where your buttons are, so it will get the width only of the region.
// d-_-b+

#3
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
so pretty much the size will always be small if I dont put text in them.

#4
ksemeks

ksemeks

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Well, if you want an empty button, you can set his preferred size.
JButton button = new JButton();
button.setPreferredSize(new Dimension(int width, int height));

The Dimension class is located in java.awt.Dimension; which you'll have to import. Or you can play with other layouts.
// d-_-b+

#5
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
Thank you