1

Is there a way to either set a max size of a button(or non re sizable), or not allow the columns in a gridbaglayout to change size if a component grows ?

i.e 
    btn.setMaxsize();
    btn.resizable(false);
    gridbaglayout.lockcolumns();

This is not what I am coding but what I am trying to achieve. Thanks for any help provided.

Elewis787
  • 27
  • 1
  • 7
  • Have you tried setting gridweight to 0? – prasanth May 02 '13 at 13:13
  • For better help sooner, post an [SSCCE](http://sscce.org). If you set the field `fill` of your `GridBagConstraint` to `GridBagConstraint.NONE` your button will always keep the same size (its preferred size). – Guillaume Polet May 02 '13 at 13:20
  • You must have something wrong in your code then. Anyway, using setMin/Max/Pref size is really not recommended. This is going down a very bad road which will eventually lead to more problems and less solutions. – Guillaume Polet May 02 '13 at 13:24
  • Check out [this question and its accepted answer](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi) – Guillaume Polet May 02 '13 at 13:25
  • Guillaume your solution works as well. I was commenting on Prasanth answer. Thank you all for the quick answers. – Elewis787 May 02 '13 at 13:28
  • I am going with guillaume polet's solution. Thanks again – Elewis787 May 02 '13 at 13:28

1 Answers1

-1

set below 3 properties with max value.

    btnNewButton.setMaximumSize(new Dimension(10, 10));
    btnNewButton.setMinimumSize(new Dimension(10, 10));
    btnNewButton.setPreferredSize(new Dimension(10, 10));
Sanjaya Liyanage
  • 4,706
  • 9
  • 36
  • 50
  • width of the button and the height is set by new Dimension(width, height) – Sanjaya Liyanage May 02 '13 at 13:15
  • 2
    Check out [this question and its accepted answer](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi). Using setMaximum/Minimum/PreferredSize is a bad idea. – Guillaume Polet May 02 '13 at 13:25
  • 1
    See also [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing](http://stackoverflow.com/q/7229226/230513)? – trashgod May 02 '13 at 13:26
  • Thanks for the additional info! – Elewis787 May 02 '13 at 13:29