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.
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.
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!)
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.
this.setBorder(new EmptyBorder(0,5,0,5)); // top, left, bottom, right
in it's constructor.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i added this code but it doesnt seem to have had any effect ??
opCombo.setRenderer(new DefaultListCellRenderer()) ;
((DefaultListCellRenderer) opCombo.ge tRenderer( )).setBord er(new EmptyBorder(0,20,0,20));
opCombo.setRenderer(new DefaultListCellRenderer())
((DefaultListCellRenderer)
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.getPreferredSi ze();
d.setSize( 250, d.getHeight() );
theComboBox.setMinimumSize (d);
theComboBox.setPreferredSi ze(d);
}
>>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.getPreferredSi
d.setSize( 250, d.getHeight() );
theComboBox.setMinimumSize
theComboBox.setPreferredSi
}
ASKER
thankyou,
they both work - i quite like the renderer solution, i just modified the constructor a little.
they both work - i quite like the renderer solution, i just modified the constructor a little.
Thanks :)
I think that if you put the JComboBox in a simple FlowLayout you'll automatically have this behaviour.