Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages
Started by Magnus
Fri, 08 Sep 2006 15:22
GridBagLayout - strange behavior?
Author: Magnus
Date: Fri, 08 Sep 2006 15:22
Date: Fri, 08 Sep 2006 15:22
49 lines
2598 bytes
2598 bytes
Hi,
I have a "strange behavior" in 2 of my windows (JFrame) on WInXP running
JRE1.4.
Example - one panel have (GBL) Grid: 5 across and 4 down
Top row looks like:
RadioButton1 (RB1), RB2, label, JComboBox, empty
Constraints
Grid Ext Insets Padd Weight Anchor Fill
components X Y W H T L B R W H X Y
---------- - - - - -- -- - --- --- -- - - ------ -----
RB1 0 0 1 1 39 40 0 0 9 -3 0 0 Center None
RB2 1 0 1 1 39 0 0 103 23 -3 0 0 C N
label 2 0 1 1 39 9 0 0 33 5 0 0 West N
JCB 3 0 1 1 39 9 0 134 154 -1 1 0 C Horiz
(All values were created in JBuilder from XY-Layout)
The problem: If a value (visible or down the list not visible) in the
JCB is large (>17 char) the label that is for RB2 is cropped. Some
changes below in the panel does also happens but what I don't understand
is why only the RB2 label is affected and not anything else on that "row".
Note: There is plenty of space in the JCB to display the full string (up
to 50 char).
Tests:
1) If I remove the padding, the RB2 label is fine but the JCB doesn't
display the full string.
2) Changing the JCB to
JCB 3 0 1 1 39 9 0 0 0 0 1 0 W None
creates a window that size everything according to the strings in
JCB. Since the JCB is empty (populated from a DB) when in design mode it
becomes hard to see the final size and layout.
3) I added a padding of W 120 and could now use a longer string but not
full length (50 char).
A constraint that I didn't play with is weightx but should not change
anything unless I resize the pane, right?
TIA,
Magnus
Re: GridBagLayout - strange behavior?
Author: Paul Furbacher [TeamB]
Date: Fri, 08 Sep 2006 21:40
Date: Fri, 08 Sep 2006 21:40
82 lines
3847 bytes
3847 bytes
If you included the actual code (stripping down to just
what you show below), it would be a lot easier for one
of us to pull it into a little test project and play
with it. As it is, I don't have the time to translate
the table below into code, but if I had the code, it
would take a minute or two to see what is happening and
what the remedy might be.
I'm suspicious of the -3 and odd paddings -- I rarely
use any padding. The extreme insets.right are also something
I would avoid. My feeling on the latter is that in most
cases they should be in the range of 8 - 12 px at most, and
balanced. Other methods for displacing far to the left or
right should be used instead.
Magnus wrote:
> Hi,
>
> I have a "strange behavior" in 2 of my windows (JFrame) on WInXP running
> JRE1.4.
>
> Example - one panel have (GBL) Grid: 5 across and 4 down
>
> Top row looks like:
>
> RadioButton1 (RB1), RB2, label, JComboBox, empty
>
> Constraints
> Grid Ext Insets Padd Weight Anchor Fill
> components X Y W H T L B R W H X Y
> ---------- - - - - -- -- - --- --- -- - - ------ -----
> RB1 0 0 1 1 39 40 0 0 9 -3 0 0 Center None
> RB2 1 0 1 1 39 0 0 103 23 -3 0 0 C N
> label 2 0 1 1 39 9 0 0 33 5 0 0 West N
> JCB 3 0 1 1 39 9 0 134 154 -1 1 0 C Horiz
>
> (All values were created in JBuilder from XY-Layout)
>
> The problem: If a value (visible or down the list not visible) in the
> JCB is large (>17 char) the label that is for RB2 is cropped. Some
> changes below in the panel does also happens but what I don't understand
> is why only the RB2 label is affected and not anything else on that "row".
>
> Note: There is plenty of space in the JCB to display the full string (up
> to 50 char).
>
> Tests:
> 1) If I remove the padding, the RB2 label is fine but the JCB doesn't
> display the full string.
>
> 2) Changing the JCB to
> JCB 3 0 1 1 39 9 0 0 0 0 1 0 W None
> creates a window that size everything according to the strings in
> JCB. Since the JCB is empty (populated from a DB) when in design mode it
> becomes hard to see the final size and layout.
>
> 3) I added a padding of W 120 and could now use a longer string but not
> full length (50 char).
>
> A constraint that I didn't play with is weightx but should not change
> anything unless I resize the pane, right?
>
> TIA,
>
> Magnus
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Re: GridBagLayout - strange behavior?
Author: Magnus
Date: Mon, 11 Sep 2006 18:33
Date: Mon, 11 Sep 2006 18:33
210 lines
8693 bytes
8693 bytes
Thanks Paul!
As I tried to describe below, I did play with padding etc. and got it to
look good. The number listed are from the automatic conversion from
XYL2GBL in JBuilder 2005 Developer.
I did a quick simulation of my Frame and got the same problem (code
below) but now I got a W-Padding of -363. Change this to -100 or so 0
and the RB2 will disappear.
The Fill and Anchor might be different but same behavior (as expected).
Other frames where the JCB is used (it is the Company Name 50 char))
where this doesn't cause a problem is where I work with sub-panels and
all fields etc are stacked vertical within said sub-panels.
--- code for test ---
package gbl;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame1 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JLabel jLabel1 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JTextArea jTextArea1 = new JTextArea();
GridBagLayout gridBagLayout1 = new GridBagLayout();
public Frame1() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
jComboBox1.addItem("1234567980");
jComboBox1.addItem("12345679801234567980");
jComboBox1.addItem("123456798012345679801234567980");
jComboBox1.addItem("1234567980123456798012345679801234567980");
jComboBox1.addItem("12345679801234567980123456798012345679801234567980");
jComboBox1.addItem("123456798012345679801234567980123456798012345679801234567980");
jComboBox1.addItem("1234567980123456798012345679801234567980123456798012345679801234567980");
jComboBox1.addItem("12345679801234567980123456798012345679801234567980123456798012345679801234567980");
jComboBox1.addItem("123456798012345679801234567980123456798012345679801234567980123456798012345679801234567980");
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(566, 300));
setTitle("Frame Title");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new
Frame1_jMenuFileExit_ActionAdapter(this));
jPanel1.setLayout(gridBagLayout1);
jRadioButton1.setText("jRadioButton1");
jRadioButton2.setText("jRadioButton2");
jLabel1.setText("jLabel1");
jTextArea1.setText("jTextArea1");
jMenuBar1.add(jMenuFile);
jMenuFile.add(jMenuFileExit);
contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.add(jRadioButton1, new GridBagConstraints(0, 0, 1, 1,
0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(28, 21, 0, 0), 7, -5));
jPanel1.add(jRadioButton2, new GridBagConstraints(1, 0, 1, 1,
0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(28, 0, 0, 0), 4, 1));
jPanel1.add(jLabel1, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(28, 8, 0, 0), 15, 6));
jPanel1.add(jTextArea1, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0
, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(11, 21, 56, 8), 117, 164));
jPanel1.add(jComboBox1, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(28, 20, 0, 70), -400, 0));
setJMenuBar(jMenuBar1);
}
/**
* File | Exit action performed.
*
* @param actionEvent ActionEvent
*/
void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
}
class Frame1_jMenuFileExit_ActionAdapter implements ActionListener {
Frame1 adaptee;
Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}
Paul Furbacher [TeamB] wrote:
> If you included the actual code (stripping down to just
> what you show below), it would be a lot easier for one
> of us to pull it into a little test project and play
> with it. As it is, I don't have the time to translate
> the table below into code, but if I had the code, it
> would take a minute or two to see what is happening and
> what the remedy might be.
>
> I'm suspicious of the -3 and odd paddings -- I rarely
> use any padding. The extreme insets.right are also something
> I would avoid. My feeling on the latter is that in most
> cases they should be in the range of 8 - 12 px at most, and
> balanced. Other methods for displacing far to the left or
> right should be used instead.
>
>
> Magnus wrote:
>> Hi,
>>
>> I have a "strange behavior" in 2 of my windows (JFrame) on WInXP
>> running JRE1.4.
>>
>> Example - one panel have (GBL) Grid: 5 across and 4 down
>>
>> Top row looks like:
>>
>> RadioButton1 (RB1), RB2, label, JComboBox, empty
>>
>> Constraints
>> Grid Ext Insets Padd Weight Anchor Fill
>> components X Y W H T L B R W H X Y
>> ---------- - - - - -- -- - --- --- -- - - ------ -----
>> RB1 0 0 1 1 39 40 0 0 9 -3 0 0 Center None
>> RB2 1 0 1 1 39 0 0 103 23 -3 0 0 C N
>> label 2 0 1 1 39 9 0 0 33 5 0 0 West N
>> JCB 3 0 1 1 39 9 0 134 154 -1 1 0 C Horiz
>>
>> (All values were created in JBuilder from XY-Layout)
>>
>> The problem: If a value (visible or down the list not visible) in the
>> JCB is large (>17 char) the label that is for RB2 is cropped. Some
>> changes below in the panel does also happens but what I don't
>> understand is why only the RB2 label is affected and not anything else
>> on that "row".
>>
>> Note: There is plenty of space in the JCB to display the full string
>> (up to 50 char).
>>
>> Tests:
>> 1) If I remove the padding, the RB2 label is fine but the JCB doesn't
>> display the full string.
>>
>> 2) Changing the JCB to
>> JCB 3 0 1 1 39 9 0 0 0 0 1 0 W None
>> creates a window that size everything according to the strings in
>> JCB. Since the JCB is empty (populated from a DB) when in design mode
>> it becomes hard to see the final size and layout.
>>
>> 3) I added a padding of W 120 and could now use a longer string but
>> not full length (50 char).
>>
>> A constraint that I didn't play with is weightx but should not change
>> anything unless I resize the pane, right?
>>
>> TIA,
>>
>> Magnus
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads