Setting JFrames minimum size

how do i set the minimum size of a JFrame
thanks
Phil

You can't set it, but you can control it by adding a component listener to the JFrame:
http://forum.java.sun.com/thread.jsp?forum=31&thread=245747

Similar Messages

  • How to set a minimum size of a JFrame

    hi freinds,
    i have written a swing application which starts like this ,
    public class workerclass extends JFrame implements ActionListener {
    blah blah blah ..
    now can you please tell me how to set a minimum size for this application once it starts so that user cant minimize it more than that minimum size.....
    when i tried
    setDefaultLookAndFeelDecorated(true);
    it did my job by setting it to a particular size which wasnt minimizable, but this default look and feel looked ugly.
    so i used system look and feel
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    but with this how do i set the minimum size..
    please do help
    and one thing more , like
    in my main Method when i say
    new workerclass().setSize(500,500); or say(100,100) or say(300,300)
    new workerclass().setVisible(true);
    the size (***,***) , doesnt reflect when my application starts, it always starts with some damn fixed size , what can be the issue .
    waiting.........
    Thanks

    how do i set my Jrame to a minimum size so that
    minimizing beyond that can be restrictedThis is what the code is all about
    don't know your code but ..
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class workerclass extends JFrame implements
    ActionListener,ComponentListener {
    public void initcomponenet()
    setJMenuBar();
    pack();
    addComponentListener(this);
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new myclass.setSize(500,500);
    new myclass().setVisible(true);
    public void componentShown(ComponentEvent e)
         public void componentResized(ComponentEvent e)
              if(getWidth()<200)//restrict width to minimum 200
                   setSize(200,getHeight());
    if(getHeight()<100)//restrict Height to minimum
    um 100
                   setSize(getWidth(),100);
         public void componentMoved(ComponentEvent e)
         public void componentHidden(ComponentEvent e)
    Thanks kanad , your code is working ... you desere lot more than a duke dollar but for now i can only give that :-( , please accept it :-)

  • How can I set the minimum size the location bar should automatically resize to

    I have moved all of my navigation buttons, location bar and tabs to be in line. This has been done to maximise the available space on screen.
    This works perfectly with two or three tabs open, but once more tabs are opened the location bar automatically shrinks to allow for more tabs and becomes unusable. I want to set the minimum size the location bar should shrink to but I do not know how to do this.
    [http://www.mediafire.com/imgbnc.php/eed5749531b3081c43186f59492500e5f089c498c0372fb6fa797b7d697826806g.jpg Screen shot displaying automatically resizing location bar]
    Any help would be appreciated.
    Thanks.

    FBZP seems to be the only way to do the minimum amout setting in standard SAP.
    You can check the BTE (Business transaction event) 00001820 for excluding the low amount items in F110. Please search SDn on how to use the BTEs.
    Regards,
    SDNer

  • How to set the minimum size of a JFrame.

    I can user JFrame.setMinimumSize() method with jdk1.6.0. But I can't find this method in jdk1.4.2. How can I do this with jdk1.4.2?

    Try google:
    http://www.google.com/search?q=jframe+minimum+size

  • How to set the minimum size of the JDialog.

    Hi Could any one tell me ,
    How to set the minimmum size of the JDailog.
    I am using the JDialog's setMinimumSize(...)
    But it is not working.....
    Regards -
    Vikas Kumar sahu

    That's pretty much all there is, although you could always add a componentlistener and manually not let the size go below your minimum.
    Or you could try overriding setSize...

  • How to set the minimum size of app window?

    Hi JavaFX experts :)
    Is it possible to limit the minimum size of application window? What would be the JavaFX equivalent of the following SWING code?
            JFrame frame = new JFrame("Application Title");
            frame.setMinimumSize(new Dimension(320, 240));
            frame.setPreferredSize(new Dimension(640, 480));Preferred or initial size was easy (width/height), but what about the minimum size?
    Stage {
        title: "Application Title"
        width: 640
        height: 480
        scene: Scene {
            content: [
                // some content
    }Thanks!

    var stage: Stage;
    var stageWidth = stage.width on replace
        if (stageWidth < 640) stageWidth = 640;
    var stageHeight = stage.height on replace
        if (stageHeight < 400) stageHeight = 400;
    stage = Stage {
        title: "Application Title"
        width: bind stageWidth with inverse
        height: bind stageHeight with inverse
        scene: Scene {
            content: [
                // some content
    }It doesn't prevent resizing to smaller dimensions but it restores to minimal dimension if done.

  • Set minimum size of JScrolPane's knob

    Hi All,
    Please suggest me a way to set a minimum size of JScrolPane's knob.
    It becomes very small when the numbers of items in the list are so much and that time knob is very small. that makes scrolling difficult to the user.
    So i want to set a minimum size of the knob.
    Please suggest the snippet of code for that

    One posible solution is to add a ComponentListener to the
    JFrame that implements ... (struggles to remember) ...
    componentResized().
    Inside componentResized(), check the size of your JFrame,
    and if it is smaller than your preferred minimal dimension,
    resize it up to your minimum.
    // in the constructor, perhaps, or initialization routine
    addComponentListener(
      newComponentAdapter()
        public void componentMoved(ComponentEvent e)
            Dimension size = e.getComponent().getSize();
            size.width = Math.max(size.width, myMinimalWidth);
            size.height = Math.max(size.height, myMinimalHeight);
            e.getComponent.setSize(size);
      }); Pity there's no setMinimumSize() like the JComponent class.
    Best of luck !
    Eric

  • How to set a minimum width and height for a stage or scene?

    Hello,
    Does anyone how to set a minimum width and height for a stage or scene?
    I tried listening for width/height property value changes and then adjust the width/height if necessary, but that causes unpleasant flickering of the window.
    In JavaFX 2.1 beta SDK for Mac OS, the Stage class has setMinWidth() and setMinHeight() functions which work very well.
    I'm wondering what's the equivalent way to do that when using the FX SDK for Windows.
    Any help is appreciated!
    Thanks.

    I was wondering how to enforce a minimum stage size with JavaFX 2.0.3.The same flickering way you are currently doing it. See: http://javafx-jira.kenai.com/browse/RT-15200 "Need a way to set the minimum size of a window"

  • How to set Minimum size of JFrame?

    Hi,
    I want to set minimum size of my JFrame. How can i set it?
    I want to maintain a minimum size while resizing the JFrame. The user should not resize beyond the minimum size of JFrame.
    Any body knows solution, please post it.
    Thanks in Advance.

    One posible solution is to add a ComponentListener to the
    JFrame that implements ... (struggles to remember) ...
    componentResized().
    Inside componentResized(), check the size of your JFrame,
    and if it is smaller than your preferred minimal dimension,
    resize it up to your minimum.
    // in the constructor, perhaps, or initialization routine
    addComponentListener(
      newComponentAdapter()
        public void componentMoved(ComponentEvent e)
            Dimension size = e.getComponent().getSize();
            size.width = Math.max(size.width, myMinimalWidth);
            size.height = Math.max(size.height, myMinimalHeight);
            e.getComponent.setSize(size);
      }); Pity there's no setMinimumSize() like the JComponent class.
    Best of luck !
    Eric

  • How to set JFrame MEX and MIN size ?

    Hello All,
    i want to set my jframe meximum and minimum size but
    i cant find any method please help me.
    i m thanksfull.
    Arif.

    In this case minimum size is 100 and max is 400!
    I hope it helps
    import java.awt.*;
    import javax.swing.JFrame;
    import java.awt.event.*;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class Frame1 extends JFrame {
    final int minw=100;
    final int maxw=400;
    final int minh=100;
    final int maxh=400;
    public Frame1() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    Frame1 frame1 = new Frame1();
    frame1.setBounds(0,0,100,100);
    frame1.setVisible(true);
    private void jbInit() throws Exception {
    this.addComponentListener(new java.awt.event.ComponentAdapter() {
    public void componentResized(ComponentEvent e){
    frame_resized();
    public void frame_resized(){
    int hh=this.getHeight();
    int ww=this.getWidth();
    if((!(minh<hh && hh<maxh))||( !(minw<ww && ww <maxw))){
    if( hh<minh)
    hh=minh;
    if( hh>maxh)
    hh=maxh;
    if( ww<minw)
    ww=minh;
    if( ww>maxw)
    ww=maxw;
    this.setSize(ww,hh);
    Bye Alessio

  • To set minimum size of flash panel

    I am developing a flash panel in PS CS5. I have tried many way to set minimum size of panel window, but they don't work. I have not idea how to do this now. I'm waiting for your HELP. Thank YOU!

    One posible solution is to add a ComponentListener to the
    JFrame that implements ... (struggles to remember) ...
    componentResized().
    Inside componentResized(), check the size of your JFrame,
    and if it is smaller than your preferred minimal dimension,
    resize it up to your minimum.
    // in the constructor, perhaps, or initialization routine
    addComponentListener(
      newComponentAdapter()
        public void componentMoved(ComponentEvent e)
            Dimension size = e.getComponent().getSize();
            size.width = Math.max(size.width, myMinimalWidth);
            size.height = Math.max(size.height, myMinimalHeight);
            e.getComponent.setSize(size);
      }); Pity there's no setMinimumSize() like the JComponent class.
    Best of luck !
    Eric

  • Have JFrame respect the minimum size (stop resizing) - Partial solution

    Hi
    I remember I searched for a solution to make JFrame respect the minimum size of itself or it's components, but unfortunately there is no solution, at least not a satisfactory one.
    The force-a-resize-if-it-gets-too-small "solution" looks really bad so I desided to drop the whole thing.
    However I've been testing around with different Look & Feels and changing the layout, and what I discovered is that when setting setDefaultLookAndFeelDecorated(true) the minimum size is respected.
    I haven't seen anyone mentioning this I thought I'd post it here.
    import javax.swing.*;
    import java.awt.*;
    class RespectMinimumSize extends JFrame {
        RespectMinimumSize() {
         setMinimumSize(new Dimension(400, 400));
         setLocationRelativeTo(null);
         pack();
         setVisible(true);
        public static void main(String [] args) {
         JFrame.setDefaultLookAndFeelDecorated(true);
         JDialog.setDefaultLookAndFeelDecorated(true); // Works with JDialog as well
         Toolkit.getDefaultToolkit().setDynamicLayout(true);
         new RespectMinimumSize();
    }

    thanks - initial testing seems to work OK.
    (I had to add a panel, to be able to set minimum size to the panel)

  • How Do You Set the Maximum Size of a JFrame?

    Can someone show me a quick example? The JFrame can be empty, I just want to know how to set it's maximum size. I tried using setMaximumSize() and it doesn't work for some reason but setMinimumSize() works fine.
    I tried it using a BoxLayout and even using null as a layout manager and can't get it to work. I heard that the other layout managers don't allow you to set the maximum size of a JFrame so that is why I tried it with the layouts that I did.
    I tried the following code (imported the necessary classes), but it does not work...
    public class MyFrame extends JFrame
        public MyFrame()
            super("TestFrame");
            setLayout( new BoxLayout(getContentPane(), BoxLayout.X_AXIS)  );       
            setMaximumSize( new Dimension(400,200));
            setSize(300,150);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible( true );                
    }// end class

    Reposted from
    {color:#0000ff}http://forum.java.sun.com/thread.jspa?threadID=5236259{color}
    @OP:
    When you repost a topic, please always provide a link to the previous post so people can check what suggestions were already offered (and didn't solve the problem).
    Better still, give a short summary of the advice you have already tried.
    I suggested setBackground(...) so you can see whether your MyFrame is actually occupying the entire real estate of the window. Looks as if trying it out (which I would have done for you if I'd been at home, where my JDK is) would have been too much effort for you.
    I'm pretty much a novice in Swing, but I can tell you this: setLayout controls the layout of components added to the JFrame, not the layout of the frame with respect to its parent container.
    Luck, Darryl

  • Set minimum size for GridBagLayout

    Hi all,
    I have a dialog which using GridBagLayout. I spent quite a lot of time to test, but still got the following problems. Could anyone give me some solutions?
    1. How do I set the dialog to have a minimum size ?
    Since the dialog is sizeable, so I have to make this limitation to prevent the dialog being too small .
    I tried the following code:
            this.getContentPane().setMinimumSize(new Dimension(686,520));
            this.setMinimumSize(new Dimension(686,520));but it's still not work... , I can still resize it too small.. any other way ?
    2. How do I set its default size when dialog pop up?
    I don't know why the dialog always auto popup in maximum size.
    I have tried to use this.setSize(new Dimension(686, 536)); inside jbInit() function, but still not work...
    Please help ... Thanks a lot.

    Why dont you try this.setResizable(false);?
    Anyway I have given a sample program here using Gridbag layout and this dialog cannot be resized.
    import java.awt.BorderLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class SunExample28 extends JDialog {
         public SunExample28() {
              setTitle("JDialog with Fixed size");
              JLabel nameLbl = new JLabel("Name:");
              JLabel ageLbl = new JLabel("Age:");
              JTextField nameFld = new JTextField(10);
              JTextField ageFld = new JTextField(10);
              GridBagConstraints gbc = new GridBagConstraints();
              Insets in = new Insets(5,5,5,5);
              JPanel compPanel = new JPanel(new GridBagLayout());
              gbc.gridx = 0;
              gbc.gridy = 0;
              compPanel.add(nameLbl,gbc);
              gbc.insets = in;
              gbc.gridx = 1;
              gbc.gridy = 0;
              compPanel.add(nameFld, gbc);
              gbc.insets = in;
              gbc.gridx = 0;
              gbc.gridy = 1;
              compPanel.add(ageLbl, gbc);
              gbc.insets = in;
              gbc.gridx = 1;
              gbc.gridy = 1;
              compPanel.add(ageFld, gbc);
              JButton okBtn = new JButton("OK");
              JButton cancelBtn = new JButton("Cancel");
              JPanel btnPanel = new JPanel();
              btnPanel.add(okBtn);
              btnPanel.add(cancelBtn);
              getContentPane().add(compPanel, BorderLayout.CENTER);
              getContentPane().add(btnPanel, BorderLayout.PAGE_END);
              setDefaultCloseOperation(DISPOSE_ON_CLOSE);
              setSize(500,300);
              setResizable(false);
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              new SunExample28().setVisible(true);
    }

  • How to set minimum size for PieChart wedge?

    The following chart has one wedge that is very thin. I know it is because the data value for that wedge is very small (262) compared to the other wedge data values, but I'd like to be able to set a minimum wedge size.
    Any ideas?
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script><![CDATA[
         import mx.collections.ArrayCollection;
         [Bindable]
         public var expenses:ArrayCollection = new ArrayCollection([
            {Expense:"Jan", Amount:2200000},
            {Expense:"Feb", Amount:4700000},
            {Expense:"Mar", Amount:2300000},
            {Expense:"Jul", Amount:262}
      ]]></mx:Script>
      <mx:Panel title="Pie Chart">
         <mx:PieChart id="myChart"
            dataProvider="{expenses}"
            showDataTips="true"
         >
            <mx:series>
               <mx:PieSeries
                    field="Amount"
                    nameField="Expense"
                    labelPosition="callout"
               />
            </mx:series>
         </mx:PieChart>
      </mx:Panel>
    </mx:Application>

    This might be close enough to what you're looking for:
    The FB 4 code is shown below:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        minWidth="955" minHeight="600">
        <fx:Script>
         <![CDATA[
            import mx.charts.HitData;
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.utils.ObjectUtil;
            [Bindable] private var Amount:String = "";
            [Bindable] private var minAmount:String = "";
            [Bindable]
            public var expenses:ArrayCollection = new ArrayCollection([
            {Expense:"Jan", Amount:2200000, minAmount:2200000},
            {Expense:"Feb", Amount:4700000, minAmount:4700000},
            {Expense:"Mar", Amount:2300000, minAmount:2300000},
            {Expense:"Jul", Amount:262, minAmount:50000}
            private function getDataTips(hitData:HitData):String {
                // add percent when the user gets the DataTip
                var percentValue:Number = (hitData.item.Amount / 9200262) * 100;
                var f:int = 3;
                if (percentValue > 1) {
                    f = 1;
                return hitData.item.Expense + ": " + percentValue.toFixed(f) + " % (" + hitData.item.Amount + ")";
            private function getData(series:PieSeries, item:Object, fieldName:String):Object {
                if (item.minAmount != 50000) {
                    return item.Amount;
                    psExpenses.setStyle("labelPosition", "callout");
                } else {
                    return item.minAmount
                    psExpenses.setStyle("labelPosition", "none");
         ]]>
        </fx:Script>
        <mx:Panel title="Pie Chart">
         <mx:PieChart id="myChart"
                 dataProvider="{expenses}" dataTipFunction="getDataTips"
                 showDataTips="true">
            <mx:series>
                <mx:PieSeries id="psExpenses" nameField="Expense" dataFunction="getData"/>
            </mx:series>
         </mx:PieChart>
        </mx:Panel>
    </s:Application>

Maybe you are looking for

  • I am unable to clear recent h istory in the Tools. The option is not accessible.

    The clear recent history option under Tools on the menu is not active. i cannot click on that option. It is in a gray faded font and i am unable to use it

  • Macbook Pro doesn't recognize monitor - extremely frustrating!

    I have had this problem ever since I started trying to use an external monitor. Essentially, when I plug in my cable (mini display to dvi, dvi to hdmi) the display blinks blue, but my monitor doesn't turn on! Everything is plugged in, the monitor wor

  • Segmentation Fault in db- put() fun with BDB ver 4.5.20/4.6.19 in linux

    I am working on porting an application that runs on sun solaris sparc (OS ver 5.8) with Berkeley DB ver 4.2.50 into suse linux [ Linux version 2.6.5-7.244-smp (gcc version 3.3.3 (SuSE Linux)) ]. I have compiled the application in linux and i am getti

  • Does Apple make a Server Rack?

    Hi All, I saw an image for an short Apple rack filled with XServers, but can find that or any other rack info on the purchasing page. If some knows where the rack info is located could you please post a link. Thank You Joe

  • Itunes syncing problem...HELP!

    Hello! I've got a REALLY annoying problem with my iPhone currently, out of nowhere it is crashing when syncing on step 2 the backup stage, I've looked through possible suggestions, tried numerous things but cant find a solution! Any ideas!?