Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #813 > unrolled thread

setting size of JComboBox

Started by"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
First post2011-04-27 15:29 +0000
Last post2011-04-27 15:29 +0000
Articles 5 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  setting size of JComboBox "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
    Re: setting size of JComb "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
      Re: setting size of JComb "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
        Re: setting size of JComb "Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
          Re: setting size of JComb "Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000

#813 — setting size of JComboBox

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
Subjectsetting size of JComboBox
Message-ID<45bc6eaf$0$5786$4c368faf@roadrunner.com>
  To: comp.lang.java.gui
Has anyone ever had issues with setting the preferred size of a 
JComboBox using GridBagLayout?  It seems the box's height is larger than 
  the JTextField's height that I create in the same window.  I can 
change the height of the JTextFields by using setPreferredSize() to 
match the JComboBox so everything is uniform but that's only because I 
can't decrease the JComboBox's height because it seems to ignore that 
call.  Any ideas?


thanks
Brandon

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#815 — Re: setting size of JComb

From"Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
SubjectRe: setting size of JComb
Message-ID<hy5vh.146315$jb3.50303@newsfe18.lga>
In reply to#813
  To: comp.lang.java.gui
Brandon McCombs wrote:
> Has anyone ever had issues with setting the preferred size of a 
> JComboBox using GridBagLayout?  It seems the box's height is larger than 
>  the JTextField's height that I create in the same window.  I can change 
> the height of the JTextFields by using setPreferredSize() to match the 
> JComboBox so everything is uniform but that's only because I can't 
> decrease the JComboBox's height because it seems to ignore that call.  
> Any ideas?
> 
> 
> thanks
> Brandon

Set the fill element on the GridBagConstraints for the JTextField.

-- 

Knute Johnson
email s/nospam/knute/

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#819 — Re: setting size of JComb

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
SubjectRe: setting size of JComb
Message-ID<45bcfcfa$0$24530$4c368faf@roadrunner.com>
In reply to#815
  To: comp.lang.java.gui
Knute Johnson wrote:
> Brandon McCombs wrote:
>> Has anyone ever had issues with setting the preferred size of a 
>> JComboBox using GridBagLayout?  It seems the box's height is larger 
>> than  the JTextField's height that I create in the same window.  I can 
>> change the height of the JTextFields by using setPreferredSize() to 
>> match the JComboBox so everything is uniform but that's only because I 
>> can't decrease the JComboBox's height because it seems to ignore that 
>> call.  Any ideas?
>>
>>
>> thanks
>> Brandon
> 
> Set the fill element on the GridBagConstraints for the JTextField.
> 

Won't that make the JTextField match the size of the JComboBox? I want 
the JComboBox to match the size of the JTextField (JComboBox has the 
larger height due to the button for the dropdown box) which doesn't work 
at the moment because it ignores the setPreferredSize() call.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#820 — Re: setting size of JComb

From"Knute Johnson" <knute.johnson@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
SubjectRe: setting size of JComb
Message-ID<ig8vh.146330$jb3.68483@newsfe18.lga>
In reply to#819
  To: comp.lang.java.gui
Brandon McCombs wrote:
> Knute Johnson wrote:
>> Brandon McCombs wrote:
>>> Has anyone ever had issues with setting the preferred size of a 
>>> JComboBox using GridBagLayout?  It seems the box's height is larger 
>>> than  the JTextField's height that I create in the same window.  I 
>>> can change the height of the JTextFields by using setPreferredSize() 
>>> to match the JComboBox so everything is uniform but that's only 
>>> because I can't decrease the JComboBox's height because it seems to 
>>> ignore that call.  Any ideas?
>>>
>>>
>>> thanks
>>> Brandon
>>
>> Set the fill element on the GridBagConstraints for the JTextField.
>>
> 
> Won't that make the JTextField match the size of the JComboBox? I want 
> the JComboBox to match the size of the JTextField (JComboBox has the 
> larger height due to the button for the dropdown box) which doesn't work 
> at the moment because it ignores the setPreferredSize() call.

JComboBoxes have a preferred size that is larger than a JTextField. 
GridBagLayout uses only preferred size, not minimum size.  So if you 
really want to make the JComboBox smaller then you will have to do some 
tricks.  Set the minimum size to 1,1 and reset the preferred size to 
match the height of the JTextField.  I think I would just let my 
JTextField get bigger to match the JComboBox but it does appear to work.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JFrame {
     String[] array = {"one","two","three"};

     public test() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setLayout(new GridBagLayout());

         GridBagConstraints c = new GridBagConstraints();
         c.insets = new Insets(2,2,2,2);

         JComboBox cb = new JComboBox(array);
         JTextField tf = new JTextField("test");

         System.out.println(cb.getMinimumSize());
         System.out.println(cb.getPreferredSize());
         System.out.println(tf.getPreferredSize());

         cb.setMinimumSize(new Dimension(1,1));
         cb.setPreferredSize(new Dimension(cb.getPreferredSize().width,
          tf.getPreferredSize().height));

         add(cb,c);
         add(tf,c);

         pack();
         setVisible(true);

         System.out.println(cb.getSize());
         System.out.println(cb.getPreferredSize());
     }

     public static void main(String[] args) {
         Runnable r = new Runnable() {
             public void run() {
                 new test();
             }
         };
         EventQueue.invokeLater(r);
     }
}

-- 

Knute Johnson
email s/nospam/knute/

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#822 — Re: setting size of JComb

From"Brandon McCombs" <brandon.mccombs@THRWHITE.remove-dii-this>
Date2011-04-27 15:29 +0000
SubjectRe: setting size of JComb
Message-ID<45bd28e1$0$5195$4c368faf@roadrunner.com>
In reply to#820
  To: comp.lang.java.gui
Knute Johnson wrote:
> Brandon McCombs wrote:
>> Knute Johnson wrote:
>>> Brandon McCombs wrote:
>>>> Has anyone ever had issues with setting the preferred size of a 
>>>> JComboBox using GridBagLayout?  It seems the box's height is larger 
>>>> than  the JTextField's height that I create in the same window.  I 
>>>> can change the height of the JTextFields by using setPreferredSize() 
>>>> to match the JComboBox so everything is uniform but that's only 
>>>> because I can't decrease the JComboBox's height because it seems to 
>>>> ignore that call.  Any ideas?
>>>>
>>>>
>>>> thanks
>>>> Brandon
>>>
>>> Set the fill element on the GridBagConstraints for the JTextField.
>>>
>>
>> Won't that make the JTextField match the size of the JComboBox? I want 
>> the JComboBox to match the size of the JTextField (JComboBox has the 
>> larger height due to the button for the dropdown box) which doesn't 
>> work at the moment because it ignores the setPreferredSize() call.
> 
> JComboBoxes have a preferred size that is larger than a JTextField. 
> GridBagLayout uses only preferred size, not minimum size.  So if you 
> really want to make the JComboBox smaller then you will have to do some 
> tricks.  Set the minimum size to 1,1 and reset the preferred size to 
> match the height of the JTextField.  I think I would just let my 
> JTextField get bigger to match the JComboBox but it does appear to work.
> 
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> 
> public class test extends JFrame {
>     String[] array = {"one","two","three"};
> 
>     public test() {
>         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>         setLayout(new GridBagLayout());
> 
>         GridBagConstraints c = new GridBagConstraints();
>         c.insets = new Insets(2,2,2,2);
> 
>         JComboBox cb = new JComboBox(array);
>         JTextField tf = new JTextField("test");
> 
>         System.out.println(cb.getMinimumSize());
>         System.out.println(cb.getPreferredSize());
>         System.out.println(tf.getPreferredSize());
> 
>         cb.setMinimumSize(new Dimension(1,1));
>         cb.setPreferredSize(new Dimension(cb.getPreferredSize().width,
>          tf.getPreferredSize().height));
> 
> 

thanks. I got it to work by doing that. I had tried to set the size 
before but couldn't get it to work. I'm not sure what the difference 
between your code and my previous code.  By the way, I was able to leave 
out the setMinimumSize() call.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web