Layout Issue

Hi,

My problem is as follows :

There is a parent Panel which has aGridBagLayout.

Inside that panel several other panels are added .

All these panels implement aGridLayout.

However there is one panel in this list which implements aGridBagLayOut. This panel constitutes of a JButton in the first row,a JText in the second row and Four elements (Three JButtons,One JComboBox)

in the third row.All the rows are set equal height.But the middle row gets compressed and gets smaller in height than the other

two rows.The source code however sets all the height to be the same across this panel for all elements.

Please help.

[701 byte] By [rm76a] at [2007-10-2 23:45:57]
# 1
Set the GridBagConstraints of all the elements to have a yWeight of 1.0.
BaltimoreJohna at 2007-7-14 16:30:24 > top of Java-index,Desktop,Core GUI APIs...
# 2
Yes I did. But it still does not work!Any other ideas?
rm76a at 2007-7-14 16:30:24 > top of Java-index,Desktop,Core GUI APIs...
# 3
I stopped reading after this bit:My problem is as follows :There is a parent Panel which has a GridBagLayout.The rest of your post is probably superfluous :o)Have a look here, https://tablelayout.dev.java.net/
itchyscratchya at 2007-7-14 16:30:24 > top of Java-index,Desktop,Core GUI APIs...
# 4

> All the rows are set equal

> height.

What do you mean "the rows are set to equal height"? You can't set row height in GridBagLayout. The layout just grabs whatever vertical space is given to the component by the parent and then distributes it to the rows acording to the yWeight values of the rows. If this problem persists even if you set the middle row yWeight to 1 (and the other rows to 0), then your problem is not with this panel, but with it's parent (or more speciffically, with the Insets you used when you added it).

If you find the GridBagLayout hard to use, give NetBeans a chance. In Netbeans 4 (or newer), when you right click on a panel which has GridBagLayout you have the option to "Customize layout", which makes for very easy GridBagLayout customization.

Message was edited by:

A.Cristescu

A.Cristescua at 2007-7-14 16:30:24 > top of Java-index,Desktop,Core GUI APIs...
# 5

I have attached the code and marked in bold where the issue occours. Please help.

** **********The show gang panel is being change to gridbagbaglayout ********************************/

GridBagLayout gridbag_gng = new GridBagLayout();

GridBagConstraints gc_gng = new GridBagConstraints();

JPanel gangs=new JPanel();

gangs.setLayout(gridbag_gng );

gangs.setBorder(new LineBorder(Color.black,1,false));

gangs.setForeground(PlanBoardStyleSheet.PANELFG);

gangs.setBackground(PlanBoardStyleSheet.PANELBG);

gc_gng.fill = GridBagConstraints.BOTH;

gc_gng.insets=new Insets(1,1,1,1);

gc_gng.weightx = 1.0;

gc_gng.weighty = 1.0;

JButton btnShowGangs=new JButton("Show Gangs");

btnShowGangs.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

btnShowGangs.setForeground(PlanBoardStyleSheet.BUTTONFG);

btnShowGangs.setBackground(PlanBoardStyleSheet.BUTTONBG);

btnShowGangs.addActionListener(listener);

gc_gng.gridx =0;

gc_gng.gridy = 0;

gc_gng.gridwidth = 4;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(btnShowGangs,gc_gng);

gangs.add(btnShowGangs);

JTextField txtGangs=new JTextField(10);

txtGangs.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

txtGangs.setForeground(PlanBoardStyleSheet.TEXTBOXFG);

txtGangs.setBackground(PlanBoardStyleSheet.TEXTBOXBG);

hmTSPanel.put("Gangs",txtGangs);

gc_gng.gridx =0;

gc_gng.gridy = 1;

gc_gng.gridwidth = 4;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(txtGangs,gc_gng);

gangs.add(txtGangs);

JLabel lblViewDt=new JLabel("View Date:");

lblViewDt.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

lblViewDt.setForeground(PlanBoardStyleSheet.LABELFG);

lblViewDt.setBackground(PlanBoardStyleSheet.LABELBG);

gc_gng.gridx =0;

gc_gng.gridy = 2;

gc_gng.gridwidth = 1;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(lblViewDt,gc_gng);

gangs.add(lblViewDt);

JButton viewDt=null;

if(container.getSelectedViewDt()==null || "".equals(container.getSelectedViewDt()))

{

Calendar cal=Calendar.getInstance(TimeZone.getTimeZone("GMT"),Locale.UK);

cal.setTime(new Date());

viewDt=new JButton(cal.get(Calendar.DATE)+"-"+month[cal.get(Calendar.MONTH)]+"-"+cal.get(Calendar.YEAR));

container.setSelectedViewDt(cal.get(Calendar.DATE)+"-"+month[cal.get(Calendar.MONTH)]+"-"+cal.get(Calendar.YEAR));

container.setLastSelectedViewDt(cal.get(Calendar.DATE)+"-"+month[cal.get(Calendar.MONTH)]+"-"+cal.get(Calendar.YEAR));

}

else

{

viewDt=new JButton(container.getSelectedViewDt());

}

if(listener!=null)

viewDt.addActionListener(listener);

viewDt.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

viewDt.setForeground(PlanBoardStyleSheet.BUTTONFG);

viewDt.setBackground(PlanBoardStyleSheet.BUTTONBG);

container.setBtnViewDt(viewDt);

gc_gng.gridx =1;

gc_gng.gridy = 2;

gc_gng.gridwidth = 1;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(viewDt,gc_gng);

gangs.add(viewDt);

String viewTimeArr[]=new String[96];

String strStartTime="00:00";

int endHr=0;

int endMin=0;

for(int rowNum=0;rowNum<96;rowNum++)

{

endHr = rowNum/4;

endMin = rowNum%4 * 15;

strStartTime=(endHr<10?"0"+endHr:""+endHr)+":"+(endMin<10?"0"+endMin:""+endMin);

viewTimeArr[rowNum] = strStartTime ;

}

JComboBox cmbViewTime=new JComboBox(viewTimeArr);

cmbViewTime.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

cmbViewTime.setForeground(PlanBoardStyleSheet.CMBBOXFG);

cmbViewTime.setBackground(PlanBoardStyleSheet.CMBBOXBG);

if(container.getFocusableTime()==null)

{

container.setFocusableTime("06:00");

cmbViewTime.setSelectedItem("06:00");

}

else

{

cmbViewTime.setSelectedItem(container.getFocusableTime());

}

cmbViewTime.addActionListener(listener);

container.setCmbViewTime(cmbViewTime);

gc_gng.gridx =2;

gc_gng.gridy = 2;

gc_gng.gridwidth = 1;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(cmbViewTime,gc_gng);

gangs.add(cmbViewTime);

JButton btnShow=new JButton("Refresh");

btnShow.setFont(PlanBoardStyleSheet.makeFont(null,null,null));

btnShow.setForeground(PlanBoardStyleSheet.BUTTONFG);

btnShow.setBackground(PlanBoardStyleSheet.BUTTONBG);

btnShow.addActionListener(listener);

gc_gng.gridx =3;

gc_gng.gridy = 2;

gc_gng.gridwidth = 1;

gc_gng.gridheight = 1;

gridbag_gng.setConstraints(btnShow,gc_gng);

gangs.add(btnShow);

rm76a at 2007-7-14 16:30:24 > top of Java-index,Desktop,Core GUI APIs...