Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2004

Tip: Looking for answers? Try searching our database.

Minimum window size

Thread view: 
Renault John - 24 Sep 2004 07:55 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.