Hi,
I have spend a lot of time looking for a solution to set a minimum size
to a window (JFrame) containing a GridBagLayout. The simple code bellow
shows a sample of my problem.
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
public class MyWindow extends javax.swing.JFrame {
public MyWindow() {
initComponents();
}
private void initComponents() {
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(new java.awt.GridBagLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Toto");
jButton1.setMinimumSize(new Dimension(150,150)) ;
jButton1.setPreferredSize(new Dimension(200,200)) ;
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.ipadx = 0 ;
c.ipady = 0 ;
c.insets = new Insets(0,0,0,0) ;
getContentPane().add(jButton1, c);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyWindow().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
}
The minimum size is not respected (at least on OS X). I have tried to
user an other layout manager but it didn't help. Does anybody knows a
workaround for a problem like this one?
Thanks for your help.
Cheers,
Renault
Babu Kalakrishnan - 24 Sep 2004 08:24 GMT
> I have spend a lot of time looking for a solution to set a minimum size
> to a window (JFrame) containing a GridBagLayout. The simple code bellow
> shows a sample of my problem.
Do you mean setting a minimum size for the Window below which the user
isn't allowed to resize it ? In which case, I'm afraid AWT/Swing doesn't
support it.
The only workarounds available are hacks (like listening to
componentResized events on the Window and setting its size back to the
minimum value if lower than a specific value).
BK
Andrew Thompson - 24 Sep 2004 08:27 GMT
On Fri, 24 Sep 2004 08:55:02 +0200, Renault wrote:
> import java.awt.Dimension;
Concise exmaple Renault.
> The minimum size is not respected (at least on OS X). I have tried to
> user an other layout manager but it didn't help.
What other layout manager? A button filling the UI
space seems perfectly suited to BorderLayout.CENTER.

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane