Setting a JLabel's minimum size

Hello,
I have a container with a GridBag layout, and when I resize to a size wher everything fits its fine, but on the bottom of the window I have a JLabel, which can be quite large sometimes. When it is large, its minimum size is the length of the string, so when I resize its container i get some big ugly scroll bars and its contents dont get any smaller, although every other component can be much smaller.
What I would like is for the JLabel to have a minimum size (say 100 pixels) and if the window is resized less than this, introduce scroll bars, otherwise just cut off some of the text, as the label isn't very important!
I have tried loads of different stuff, the most obvious being JLabel.setMinimumSize(new Dimension(100,16)); but nothing seems to have worked, can anyone help?

         public void updateVideoInfo(){
          String str = " ";
          str = "  " + videoData.getCurrentCameraProperties().getDeviceName()+" at " + videoData.getWidth() + " by " + videoData.getHeight();
          videoInfo.setText(str);
          int width = this.getSize().width - play.getSize().width - stop.getSize().width;
          videoInfo.setPreferredSize(new Dimension(width-15,16));
     public void validate(){
          updateVideoInfo();
     }I did a quick work arround, which I had tried before but didnt work for some reason... but has now
But this would be awfull to change If i ever add anything in the future so I will look at what you said!

Similar Messages

  • 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)

  • 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);
    }

  • Setting JLabel's default size

    Hi:
    I've had a problem of setting JLabel's size. I used several methods such as setMaximumSize() and setMinimumSize() to set the size of JLabel so that it will have a defined size, no matter how much text it contains. But it doesn't work.
    The JLabel is added in a JPanel. I've also tried to use those setSize() methods on JPanel, it doesn't work either.
    Please help!
    thanks!

    Which layout manager are you using? Not all layout managers use maximum size and minimum size -- for example GridLayout will size your labels to fit exactly in the grid regardless.

  • 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 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

  • 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

  • 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

  • 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

  • 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.

  • 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

  • Window.resizeTo in addon (overlay commonDialog) does not resize after some minimum size in FF v17 & 18

    I created an addon which overlay commonDialog.xul.
    In the load event, window.resizeTo is called and set to a very small size (like 10x10) so it is almost invisible to users.
    This works fine in FF 15. After upgrading to FF 17 or FF 18, this stops working.
    When I set the size big, it works fine. When setting it to a small size, it seems like when hitting a limit, the window size stays the same. The window size is the same when setting to 10x10 or 100x100.
    This is on a MAC, but same behavior is observed on Windows too.
    It seems like there is a minimum size predefined and the window does not get smaller than that.
    Aren't we supposed to be able to resize the window as we wish in the addon?

    If you create your own window with a unique ID then it should be possible to create more specific CSS rules for that window.
    How (when) do you resize that window when you need it to show with the default dimensions?
    If you have specific questions about developing extensions then it is best to ask advice at the MozillaZine Extension Development forum.
    *http://forums.mozillazine.org/viewforum.php?f=19
    The helpers at that forum are more knowledgeable.<br>
    You need to register at the MozillaZine forum site in order to post at that forum.

  • JSplitPane resize problem (not a minimum size problem though)

    I created a JSplitPane and put a JPanel in both the top and bottom sides. This JSplitPane is in the center section of a BorderLayout of a JFrame. The minimum sizes are set and I can move the divider bar all I want. Instead, I am having trouble resizing the window and having the divider bar becoming shorter. When I resize the window, the width of the images dont become smaller even though they have a minimum size set to a minimal size and there is space in the panels that can be reduced.
    Here is the code that I am playing with to get this to work. Any ideas how to get this to work? It works in the SwingSet2 Demo, but there is so much extra junk in there that I cant determine the differences with what I'm doing.
    Thanks,
    J.R.
    import java.awt.*;
    import javax.swing.*;
    public class SplitPaneJFrame extends JFrame {
    JPanel statsPanel = new JPanel();
    JPanel northPanel = new JPanel();
    JPanel southPanel = new JPanel();
    JSplitPane splitPane;
    public SplitPaneJFrame () {
    setupGUI();
    private void setupGUI() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screenSize.width, screenSize.height - 64);
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    p1.setMinimumSize(new Dimension(100,100));
    p1.setPreferredSize(new Dimension(500,250));
    p1.setBackground(Color.yellow);
    p1.add(new Button("This is a button for the top area"));
    JPanel p2 = new JPanel();
    p2.setMinimumSize(new Dimension(100,100));
    p2.setPreferredSize(new Dimension(500,250));
    p2.setBackground(Color.red);
    p2.add(new Button("This is a button for the bottom area"));
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, northPanel, southPanel);
    splitPane.setOneTouchExpandable(true);
    northPanel.setLayout(new BorderLayout());
    northPanel.setMinimumSize(new Dimension(100,100));
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
    panel.setPreferredSize(new Dimension((int)Math.min(1012, getSize().width * .75), (int)(getSize().height * 0.75)));
    panel.setMinimumSize(new Dimension(100,100));
    panel.add(p1);
    northPanel.add(panel);
    southPanel.setLayout(new BorderLayout());
    southPanel.setMinimumSize(new Dimension(100,100));
    southPanel.add(p2);
    splitPane.setDividerLocation(0.75);
    c.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
    c.setBackground(Color.white);
    JPanel jp = new JPanel();
    jp.add(splitPane);
    c.add(BorderLayout.CENTER, jp);
    setVisible(true);
    public static void main(String args []) {
    new SplitPaneJFrame();

    Hmm. Ok, that was dumb on my part :-) Sometimes you just need a second set of eyes.
    Any Idea why, after I make the fix, the top panel does not resize at all? The bottom one does, but the inner panels of the top do not. I added a second panel to the top and it flowed under the first one panel (p1) as the outter panel (northPanel) resized, but the inner panel stays the same size regardless of how much I narrow the window.
    J.R.

  • Minimum size of SGA for the recovery catalog db ?

    I've created a recovery catalog database and by default the total size of the SGA is 180MB. Problem is, there isnt' much memory on development server to run the target and recovery catalog database (catdb).
    Would it be possible to startup catdb with an SGA of size 10 MB or so? What's the minimum size? I figured since catdb is only used as for the recovery catalog and would rarely be access or changed, it doesn't need to use that much memory.
    Thanks in advance

    Hi David,
    In 10g, the minimal shared_pool_size is 120M, otherwise you will get
    ORA-00371: not enough shared pool memory, should be atleast 123232153 bytes
    You can set java_pool_size to 0, which is NOT the default.
    You could also set the large_pool_size to 0, but I am not sure this is recommended.
    In 8.0 shared_pool_size could be as low as 300K. Read your Reference manual for the values specifics to your version
    HTH
    Laurent Schneider
    OCM DBA

Maybe you are looking for

  • "Attempting to copy to the disk failed. An unknown error occurred (-69)"

    Hello, If someone could help me you would make me very happy! I have had loads of different computers and 2 different ipods all on the same itunes account. I now have my own laptop for keeps so decided to deauthorise all computers and start afresh. T

  • Login  or creation of user from custom pipelineservlet.

    Hi, we have a requirement like user will be loggedin or created in one of custom request pipeline servlet.  In this pipeline we will invoke a webservice call. Using this response, user will be either loggedin or created if not exist already. To creat

  • Permanently printing the date on photos?

    I take lots of pictures of my grandchildren, & will print 40 to 50 different shots at a time, using CS3 or Elements 6; is there a way to get the date to default on the pictures or do I have to put it on each individual photo?

  • Skype is Deactivating subscription without proof

    Hi, I am using Skype unlimited subscription for India from last 5 months. Suddenly, today I received a email from Skype saying that  "we have noticed some prohibited usage of your subscription."  This is so funny, because, I was not in town from 26th

  • Helpful advice for new high definition camcorder owner

    I recently purchased a new camcorder to record games for our high school basketball team. (Canon vixia HF R10)  I have been playing around with the settings to find the best setting for recording fast moving action.  Any advice on settings?