JFram or Jpanel maximum size

How should I set maximum and minimum size of JFrame (or JPanel using BorderLayout) ? Please note setPreferredSize() and setMaximumSize() are not effective.
Thanks

You can't set the min/max size of a JPanel in a BorderLayout.
You can't directly set the min/max size of a JFrame, but you can add a ComponentListener the the JFrame and resize the JFrame when it exceeds you specified sizes.
Search the forum using "+maximum +addcomponentlistener".
Of course since this is a Swing question, you should be searching the Swing forum.

Similar Messages

  • How to set an empty JPanel to maximum size?

    Hello!
    I created class extends JFrame.
    I want this maximum size so I set the minimum size as screen size:
    setSize(screenWidth,screenHeight);
    Now I added an empty JPanel,
    and I want it to be the maximum size.
    But the problem is - I don't know what is the maximum of the current size without the frame borders. I mean, after set it to maximum size (I don't know how),
    I could get the width and height of the current size without the frame borders by:
    frame.getContentPane().getSize();
    In conclusion, I want to set an empty JPanel to maximum size and get JFrame size without the frame borders.
    Thanks!

    800512 wrote:
    Now I added an empty JPanel,
    and I want it to be the maximum size.Define "maximum size". You want it to fill the screen or you want it to be the maximum size inside its container (JFrame in this case)?
    You cannot make a component break out of its container, that's for sure. So assuming you want the component to grow to the maximum size inside its container, that should already happen when you add the component to the CENTER position of the JFrame's container. By default it has a BorderLayout.

  • 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

  • How Do You Set a JFrame's Maximum Size?

    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.

    Darryl.Burke wrote:
    Are you displaying your MyFrame as a top-level window or adding it to a parent JFrame with null or BoxLayout set?
    Maybe the method you're looking for is setMaximizedBounds(Rectangle bounds)
    You could also try this: setBackground(...) to something other than the default background and run your program again.
    I'm at work and can't try ou any of my suggestions, so please post back if you get any progress.
    dbsetMaximizedBounds is a little better but not really what I was looking for. I can still make the window go passed the set boundaries when the window hasn't been maximized.
    Also, I checked that method setBackground, that only seems to change the color, is that the same method you were referring to?

  • How to determine the maximum size of JFrame?

    I am using JDK1.2 to develop an application. I have
    a problem to handle the maximum size of of JFrame.
    If the user clicks the maximum icon or double-clicks
    the title bar from the JFrame, the JFrame becomes
    maximum. How can I determine the state of maximization? I need to bring different views if the
    JFrame is maximum or minimum. I knew JDK1.4 can
    handle this problem. Or using JNI, either. Does
    anyone know other ways to handle this?
    Thanks,
    Peter

    So that you won't have to wait forever:
    Sorry, pal, the only way is JNI. I researched this earlier for 1.2, but can't find it right now in the database. They finally added it to 1.4.
    Good luck.

  • JFrame maximum size

    Hi! I'm using a JFrame in a game I'm developing, and this should be resizeable within some bounds. This works fine for the minimum size, the user is unable to even try to resize the frame smaller than what I've set as the minimum size. But it seems like maximum size is a different issue - I can't find a way to bound how large the user may expand the frame. Of course, when it's extended to a larger size than my specified maximum, it's resized back to the maximum size (using a ComponentListener to detect resize attempts - this has to be done because I need a constant aspect ratio - and a maximum size). But I don't like this solution very much, I would rather find it impossible to even try to extend the frame larger than the bounds - in the same way one can set the bounds for the minimum size. Please help me!
    Any suggestions anyone?

    See [http://forums.sun.com/thread.jspa?threadID=5342801]
    The real issue is that setMinimumSize is declared in Window whereas setMaximumSize is declared in Component. Thus the two methods do not have complementary connotations.
    Experimenting with workarounds posted on those bug report pages, I think this is the cleanest solution, even if it does involve using a painting method for something other than painting -- normally to be avoided. SSCCE:import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    public class MaxSizeFrame {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new MaxSizeFrame().makeUI();
       public void makeUI() {
          final JFrame frame = new JFrame("") {
             @Override
             public void paint(Graphics g) {
                Dimension d = getSize();
                Dimension m = getMaximumSize();
                boolean resize = d.width > m.width || d.height > m.height;
                d.width = Math.min(m.width, d.width);
                d.height = Math.min(m.height, d.height);
                if (resize) {
                   Point p = getLocation();
                   setVisible(false);
                   setSize(d);
                   setLocation(p);
                   setVisible(true);
                super.paint(g);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 400);
          frame.setMaximumSize(new Dimension(500, 500));
          frame.setMinimumSize(new Dimension(300, 300));
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    }This way, instead of repeated flickering, there is just one flicker as the specified maximum size is crossed.
    db

  • Problem with the JFrame maximum size

    Dear all,
    I need to make my application expand to the maximum screen size when
    the user first starts it. I am using hte following code:
    frame.setSize(getMaximumSize());          
    however if my JFrame has a border layout and I have added a component at the page end
    "add(new JLabel("hello"), BorderLayout.PAGE_END);"
    this component is not displayed on the screen until I maximize the JFrame manually by clicking on
    the default "Maximize" button at the right top corner?
    Does anyone know how to get the JFrame occupy the maximum screen size where all of the
    components would be visible?
    Kanita

    Solved:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=546044

  • Problem with JFrame and JPanel

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FinalTest extends JFrame
         public JPanel contentPane;
         public JImagePanel imgPanel;
         private JLabel[] cottageIcon;
         private boolean keepMoving;
         private int selectedCottage;
         public FinalTest()
              super();
              initializeComponent();
              addActionListeners();
              this.setVisible(true);
         private void initializeComponent()
              contentPane = (JPanel)getContentPane();
              contentPane.setLayout(null);
              imgPanel = new JImagePanel("back.png");
               imgPanel.setLayout(null);
              imgPanel.setBackground(new Color(1, 0, 0));
                   addComponent(contentPane, imgPanel, 10,10,imgPanel.getImageWidth(),imgPanel.getImageHeight());
              cottageIcon = new JLabel[6];
              keepMoving = true;
              selectedCottage = 0;
              cottageIcon[0] =  new JLabel();
              //This component will never be added or shown, but needs to be there to cover for no cottage selected
              for(int a = 1; a < cottageIcon.length; a++)
                   cottageIcon[a] = new JLabel("C" + (a));
                   cottageIcon[a].setBackground(new Color(255, 0, 0));
                    cottageIcon[a].setHorizontalAlignment(SwingConstants.CENTER);
                    cottageIcon[a].setHorizontalTextPosition(SwingConstants.LEADING);
                    cottageIcon[a].setForeground(new Color(255, 255, 255));
                    cottageIcon[a].setOpaque(true);
                    addComponent(imgPanel,cottageIcon[a],12,(a-1)*35 + 12,30,30);
                this.setTitle("Cottage Chooser");
                this.setLocationRelativeTo(null);
              this.setSize(new Dimension(540, 430));
         private void addActionListeners()
              imgPanel.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        imgPanel_mousePressed(e);
                   public void mouseReleased(MouseEvent e)
                        imgPanel_mouseReleased(e);
                   public void mouseEntered(MouseEvent e)
                        imgPanel_mouseEntered(e);
              imgPanel.addMouseMotionListener(new MouseMotionAdapter()
                   public void mouseDragged(MouseEvent e)
                        imgPanel_mouseDragged(e);
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         private void imgPanel_mousePressed(MouseEvent e)
              for(int a = 1; a < cottageIcon.length; a++)
                   if(withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()))
                        System.out.println("B" + withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()));
                        selectedCottage = a;
                        keepMoving = true;
         private void imgPanel_mouseReleased(MouseEvent e)
              System.out.println("called");
              selectedCottage = 0;
              keepMoving = false;
         private void imgPanel_mouseDragged(MouseEvent e)
               System.out.println("XXX" + Math.random() * 100);
              if(keepMoving)
                   int x = e.getX();
                    int y = e.getY();
                    if(selectedCottage!= 0)
                         cottageIcon[selectedCottage].setBounds(x-(30/2),y-(30/2),30,30);
                    if(!legalBounds(imgPanel,cottageIcon[selectedCottage]))
                        keepMoving = false;
                        cottageIcon[selectedCottage].setBounds(imgPanel.getWidth()/2,imgPanel.getHeight()/2,30,30);
              System.out.println(cottageIcon[selectedCottage].getBounds());
         private void imgPanel_mouseEntered(MouseEvent e)
               System.out.println("entered");
         private void but1_actionPerformed(ActionEvent e)
              String input = JOptionPane.showInputDialog(null,"Enter selected cottage");
              selectedCottage = Integer.parseInt(input) - 1;
         public boolean legalBounds(Component containerComponent, Component subComponent)
              int contWidth = containerComponent.getWidth();
              int contHeight = containerComponent.getHeight();
              int subComponentX = subComponent.getX();
              int subComponentY = subComponent.getY();
              int subComponentWidth = subComponent.getWidth();
              int subComponentHeight = subComponent.getHeight();
              if((subComponentX < 0) || (subComponentY < 0) || (subComponentX > contWidth) || (subComponentY > contHeight))
                   return false;
              return true;
         public boolean withinBounds(int mouseX, int mouseY, Rectangle componentRectangle)
              int componentX = (int)componentRectangle.getX();
              int componentY = (int)componentRectangle.getY();
              int componentHeight = (int)componentRectangle.getHeight();
              int componentWidth = (int)componentRectangle.getWidth();
              if((mouseX >= componentX) && (mouseX <= (componentX + componentWidth)) && (mouseY >= componentY) && (mouseY <= (componentY + componentWidth)))
                   return true;
              return false;
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              FinalTest ft = new FinalTest();
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class JImagePanel extends JPanel
      private Image image;
      public JImagePanel(String imgFileName)
           image = new ImageIcon(imgFileName).getImage();
        setLayout(null);
      public void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, null);
      public Dimension getImageSize()
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
             return size;
      public int getImageWidth()
                int width = image.getWidth(null);
                return width;
      public int getImageHeight()
              int height = image.getHeight(null);
              return height;
    }Now the problem I'm having is changing that class to a JFrame, it seems simple but I keep having problems like when it runs from another JFrame nothing pops up. I can do it like this:
    FinalTest ft = new FinalTest();
    ft.setVisible(false);
    JPanel example = ft.contentPanehowever I will probably be marked down on this for bad code. I'm not asking for the work to be done for me, but I'm really stuck on this and just need some pointers so I can carry on with the project. Thanks,
    Steve

    CeciNEstPasUnProgrammeur wrote:
    I'd actually consider your GUI being a JPanel instead of a JFrame quite good design - makes it easy to put the stuff into an applet when necessary...
    Anyway, you should set setVisible() to true to make it appear, not to false. Otherwise, I don't seem to understand your problem.That is actually my problem. I am trying to convert this JFrame to a JPanel

  • GUI - Set Maximum Size

    Hello,
    I tried setting the maximum size of the screen using this:
    WelcomeScreen screen2 = new WelcomeScreen();
                             screen2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                             //screen1.setSize(550, 100);
                             screen2.setSize(screen2.getMaximumSize());But it is bigger than the screen, not by much, but still bigger and also, the maximize icon is present (normally when I window is fully maxed it will appear as a restore icon)
    Please help!

    Still posting in the wrong forum.
    Do you not understand the concept of actually searching a forum "BEFORE" posting a question?
    This question is asked and answered all the time in the Swing forum. So search there. If you don't find your answer then you post your question there so that people who actually do search the forum first can benefit from the answer given.

  • Can't change Canvas's Maximum Size

    Hi, I am trying to make a program which has a frame which is fullscreen and a canvas which is the same size.
    So far I have got this:
    JFrame frame = new JFrame("Screensaver");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Toolkit tk = Toolkit.getDefaultToolkit(); 
    screenWidth = ((int) tk.getScreenSize().getWidth()); 
    screenHeight = ((int) tk.getScreenSize().getHeight()); 
    frame.setSize(screenWidth, screenHeight); 
    frame.setUndecorated(true);
    frame.setResizable(false);
    Canvas canvas = new Canvas();
    Dimension screenSize = new Dimension(screenWidth, screenHeight);
    canvas.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0); } });
    frame.getContentPane().add(canvas, BorderLayout.CENTER);          
    frame.setVisible(true);
    canvas.setMaximumSize(screenSize);
    canvas.setSize(screenSize);Note: At the beginning of the class is:
    public int screenWidth.;
    public int screenHeight;But the canvas still won't draw larger than the default maximumSize.
    As soon as I change the maximumSize, and then look at it again, it's gone back to the default!
    Anyone have any idea why?

    Do you want a [full screen exlcusive|http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html] window or just a window that happens to be the size of the desktop (minus the area of the taskbar)?
    But the canvas still won't draw larger than the default maximumSize.I'm not sure how to interpret this statement. You've set the maximum size to the the desktop. So are you saying you can't draw beyond the desktop? Are you using canvas.getGraphics() by any chance?
    As soon as I change the maximumSize, and then look at it again, it's gone back to the default!The canvas is added to the content pane in the BorderLayout.CENTER region. And it's the only component in there. Hence, it will be the same size as the content pane (which is the same size as the frame) regardless of what size or preferred size you may set on it. This is to be expected though. BorderLayout is allowed to resize the center component to take up the extra space.

  • Resizing JFrames and JPanels !!!

    Hi Experts,
    I had one JFrame in which there are three objects, these objects are of those classes which extends JPanel. So, in short in one JFrame there are three JPanels.
    My all JPanels using GridBagLayout and JFrame also using same. When I resize my JFrame ,it also resize my all objects.
    My Problem is how should i allow user to resize JPanels in JFrame also?? and if user is resizing one JPanel than other should adjust according to new size ...
    Plese guide me, how should i do this ...
    Thanknig Java Community,
    Dhwanit Shah

    Hey there, thanx for your kind intereset.
    Here is sample code .
    In which there is JFrame, JPanel and in JPanel ther is one JButton.Jpanel is added to JFrame.
    I want to resize JPanel within JFrame,I am able to do resize JFrame and JPanel sets accroding to it.
    import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class FramePanel extends JFrame {
    JPanel contentPane;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    public FramePanel() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    FramePanel framePanel = new FramePanel();
    private void jbInit() throws Exception {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(gridBagLayout1);
    this.setSize(new Dimension(296, 284));
    this.setTitle("Frame and Panel Together");
    MyPanel myPanel = new MyPanel();
    this.getContentPane().add(myPanel);
    this.setVisible(true);
    class MyPanel extends JPanel {
    public MyPanel() {
    this.setSize(200,200);
    this.setLayout(new FlowLayout());
    this.setBackground(Color.black);
    this.setVisible(true);
    this.add(new JButton("Dhwanit Shah"));
    I think i might explained my problem
    Dhwanit Shah
    [email protected]

  • Set Maximum size for a subpanel created with splitter bars in LV8

    Does anyone know how to set the Maximum size for a subpanel created with asplitter bar? If I show one cluster in the subpanel and use the scroll bar to scroll, I can see more (blank) area than I want. I just want the user to be able to scroll a cluster within a subpanel while the cluster is larger than the view area of the subpanel. I don't want to let the user scroll outside the cluster.
    Ravi Beniwal

    I apologize for the mixup in terminology. Please read Pane wherever the word Subpanel was used.
    Please see the attached VI for a description of my problem.
    I would really appreciate any help with this.
    Ravi Beniwal
    Attachments:
    Pane Scrolling Problem.vi ‏10 KB

  • Set maximum size in Text Form Field Options for a field in bi publisher RTF

    Hi All,
    How to set maximum size in Text Form Field Options for a field in bi publisher RTF.
    I have a RTF whch is having a field in that i need to add some validation condition but after adding certain condition in Add help text tab ,it is not accepting after certain length, how i can increase the length to unlimited,please help me on this
    Thnaks

    Form fields have some restrictions if your are using version lower than 11g.
    They can accommodate only 393 chars. You can add the text in both status bar and help key, which can in total consume 393 chars.
    If your code logic is more than that, it can be split into multiple form fields as Avinash suggested or you can use sub template logic and handle coding over there. Again in sub template code can be within/outside form fields.
    So there is no option for user to increase the size of form field.

  • SharePoint Foundation 2010 maximum size WID

    Hi,
    I've installed SharePoint Foundation 2010 using the Windows Internal Database. I'm a bit confused about the maximum size of the database. On several websites I read that the max size for an SQL express database is 4GB.
    Is this the same as the Windows Internal Database? Or can it grow bigger?

    Are you sure you mean the Windows Internal Database? The SharePoint foundation installer will install SQL Server Express edition.

  • Windows Server 2008 R2 Security Event Log Maximum Size

    I have a customer with logging requirements on domain controllers that are exceeding the maximum log size they have configured for the security log.  When they attempted to increase the maximum size of the security event log via Group Policy, the settings
    did not take effect.  When an attempt was made to increase the security event log manually on the domain controller via the properties of the log, an error is generated whenever the value was changed.
    The Maximum Log Size specified is not valid.  It is too large or too small. The Maximum Log Size will be set to the following: 196608 KB
    The 196608 KB value is the value that it is currently set at.  Testing on other logs, application, system, has lead to the same result.  
    wevtutil.exe sl security /ms:<n> produces similar results.  There is no error message given but the value doesn't change when you run wevtutil.exe gl security
    When viewing the registry value MaxSize under HKLM\Current Control Set\Services\EventLog\Security the change is reflected, but the log does not seem to get any larger.  
    What one would expect to be a two minute change in a group policy object has turned into something much more difficult.  Any idea what could be causing this?
    Joseph M. Durnal MCM: Exchange 2010 MCITP: Enterprise Messaging Administrator, Exchange 2010 MCITP: Enterprise Messaging Administrator, MCITP: Enterprise Administrator

    I verified that it was not another policy - the domain is pretty simple without many policies, only policies applied are:
    Default Domain Policy (no event log settings)
    Company Domain Policy (no event log settings)
    Default Domain Controller Policy (no event logs settings)
    Company Domain Controller Policy (...\Event Log\Maximum security log size 4194240 kilobytes)
    The value was 196608 before, the plan was to change the group policy setting to 4194240 and I expected it to be that easy.  However, the values didn't change.
    4194240 is divisible by 64
    Used multiple tools to try and change
    Group Policy
    Event Viewer
    wevtutil.exe
    registry editor
    While some of the methods display a larger event log, the actual size of the event log still seems to be limited to 196608 kb.  
    Thanks,
    Joe
    Joseph M. Durnal MCM: Exchange 2010 MCITP: Enterprise Messaging Administrator, Exchange 2010 MCITP: Enterprise Messaging Administrator, MCITP: Enterprise Administrator

Maybe you are looking for

  • Doubt in "GUI_FILE_SAVE_DIALOG"

    Hi All, (1).When calling this F.M and saving the file , if the file already exists it gives the message "file already exists" with the tick mark like info message. If i want the error message "X" what should i do?? (2). What is the extend button for

  • Data Collection task error (Item  is not defined in Cons Chart of Accts 01)

    Dear Experts, While executing Data collection task, I am getting error "Item  is not defined in Cons Chart of Accts 01", What could be the reason? (Many Items are getting collected in target, but at the topline this error is been shown) Regards Rites

  • Translucent menu bar

    With the OS 10.5.5 update my menu bar has gone back to being transparent on my iMac PPC G5. On my MacBookPro I have an option under Preferences>Desktop to check (or uncheck) "Translucent Menu Bar". Not so with the iMac. Is there a Terminal command fo

  • Datasource as a function module

    hi,   I am looking for a sample code to use function module as a datasource.   Is there any document which i can use for this ? Thanks in advance.

  • Gray screen on start up

    I just purchased a Ibook g4 model A1133 Built 7/5/05. When I start it a grey screen appears with the statement to reboot select mac-boot - to shut down select shut-down. When i reboot I get a revolving question mark and reading the manual it says to