Article View: borland.public.jbuilder.java.swing
Article #192Re: GridBagLayout - strange behavior?
From: 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
>
>
Technical Details
Message-ID:
<4505ac00$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45018ac6@newsgroups.borland.com> <4501e33d@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,b9c2cd48df0ef75b X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 11 Sep 2006 14:33:36 -0400 From: Magnus <magnus_bjorkman@yahoo.com> User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: GridBagLayout - strange behavior? References: <45018ac6@newsgroups.borland.com> <4501e33d@newsgroups.borland.com> In-Reply-To: <4501e33d@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.149.234.69 Message-ID: <4505ac00$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1157999616 24.149.234.69 (11 Sep 2006 11:33:36 -0700) Lines: 210 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail