Link to home
Start Free TrialLog in
Avatar of cathalmchale
cathalmchale

asked on

iPadx

Hi,

I quite like the iPad functionality in GridBagLayout as it means I can for example, set a JComboBox so that its minimum size will always be big enough to display all the text and not have "..."
  I'm using a different layout manager and I want this iPad functionality. I guess I can get it by specifying a fixed minimum size, but then I have to specify a fixed Dimension - with iPadx I could just do iPadx = 10;  and not have to worry about the component height, so if I'm never fixing any components height then it is just using the swing defaults which is what I want.

Badly worded question, but basically how do I have iPadx functionality using a different layout manager other than GridBagLayout??

Cheers,
Cathal.
Avatar of zzynx
zzynx
Flag of Belgium image

>> set a JComboBox so that its minimum size will always be big enough to display all the text and not have "..."
I think that if you put the JComboBox in a simple FlowLayout you'll automatically have this behaviour.
Avatar of cathalmchale
cathalmchale

ASKER

>> I think that if you put the JComboBox in a simple FlowLayout you'll automatically have this behaviour.

perhaps, but if i want it to be a little bit bigger again eg, 5 or 10 pixels bigger (so that it doesnt appear squashed - a little bit of breathing room!)
That's something I solve by setting my own ListCellRenderer which has

           this.setBorder(new EmptyBorder(0,5,0,5));  // top, left, bottom, right

in it's constructor.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i added this code but it doesnt seem to have had any effect ??

opCombo.setRenderer(new DefaultListCellRenderer());
((DefaultListCellRenderer)opCombo.getRenderer()).setBorder(new EmptyBorder(0,20,0,20));
I've re-read your question:
>>I guess I can get it by specifying a fixed minimum size, but then I have to specify a fixed Dimension -
>>with iPadx I could just do iPadx = 10;  and not have to worry about the component height,
>>so if I'm never fixing any components height then it is just using the swing defaults which is what I want.

Try this in the above code:

    public ComboDemo() {
        initComponents();
       
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        model.addElement("Element one");
        model.addElement("Element two");
        model.addElement("Element eleven");
        model.addElement("This is a rather long one");
        theComboBox.setModel(model);

        Dimension d = theComboBox.getPreferredSize();
        d.setSize( 250, d.getHeight() );
        theComboBox.setMinimumSize(d);
        theComboBox.setPreferredSize(d);
    }
thankyou,
they both work - i quite like the renderer solution, i just modified the constructor a little.
Thanks :)