aspose file tools
The moose likes Swing / AWT / SWT / JFace and the fly likes Gridag-Layout problem in motif look and feel. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Gridag-Layout problem in motif look and feel." Watch "Gridag-Layout problem in motif look and feel." New topic
Author

Gridag-Layout problem in motif look and feel.

nretharekar
Greenhorn

Joined: Sep 04, 2001
Posts: 2
I have created GUI window using gridbaglayout. Window contains 1 columns and 2 rows. First and second row contains two JButton with no vertical space. If i set java and window look and feel it work perfectly fine but when i set motif look and feel vertical space automatically appears. Not able to understand. If somebody is having solution please let me know as early as possible.
Attaching code for ur reference
import java.awt.*;
import java.awt.event.*;
import java.awt.Font;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import com.sun.java.swing.plaf.motif.MotifLookAndFeel;


public class UIBButtonTest extends JFrame
{

public UIBButtonTest(String strBorderName,boolean bPaintBorder)
{

JPanel buttonTestPanel;
GridBagLayout UIBButtonTestGridBagLayout;
GridBagConstraints UIBButtonTestGridBagConstraints;
Border UIBButtonTestEtchedBorder,UIBButtonTestTitleBorder;
JButton objButtonOne=null,objButtonTwo=null;

try
{
//UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
// UIManager.put("Button.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ToggleButton.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("RadioButton.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("CheckBox.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ColorChooser.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ComboBox.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("Label.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("List.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("MenuBar.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("MenuItem.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("RadioButtonMenuItem.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("CheckBoxMenuItem.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("Menu.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("PopupMenu.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("OptionPane.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("Panel.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ProgressBar.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ScrollPane.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("Viewport.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TabbedPane.font",new Font("dialog",Font.BOLD,10));
// UIManager.put("Table.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TableHeader.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TextField.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("PasswordField.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TextArea.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TextPane.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("EditorPane.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("TitledBorder.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ToolBar.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("ToolTip.font",new Font("dialog",Font.PLAIN,10));
// UIManager.put("Tree.font",new Font("dialog",Font.PLAIN,10));
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception e)
{
}
setTitle("Button Test ");
setSize(400,400);
setLocation(100,100);

//Window listener
addWindowListener(new WindowAdapter ()
{
public void windowClosing(WindowEvent e)
{
dispose();
}
});

Container contentPane = getContentPane();

buttonTestPanel = new JPanel();
UIBButtonTestGridBagLayout = new GridBagLayout();
UIBButtonTestGridBagConstraints= new GridBagConstraints();
UIBButtonTestEtchedBorder = BorderFactory.createEtchedBorder();

if((strBorderName!=null) || !strBorderName.equals(""))
{
UIBButtonTestTitleBorder = BorderFactory.createTitledBorder(UIBButtonTestEtchedBorder,strBorderName,
TitledBorder.LEFT,TitledBorder.TOP);
}
else
{
UIBButtonTestTitleBorder = BorderFactory.createTitledBorder(UIBButtonTestEtchedBorder,"",
TitledBorder.LEFT,TitledBorder.TOP);
}

//set the border to the panel
if(bPaintBorder)
{
buttonTestPanel.setBorder(UIBButtonTestTitleBorder);
}
buttonTestPanel.setLayout(UIBButtonTestGridBagLayout);
//buttonTestPanel.setLayout(new GridLayout(2,1,0,0));

objButtonOne = new JButton("Button1");
objButtonOne.setPreferredSize(new Dimension(60,40));
//buttonTestPanel.add(objButtonOne);
addComp(objButtonOne,UIBButtonTestGridBagConstraints,buttonTestPanel,1,1,1,GridBagConstraints.WEST);

objButtonTwo = new JButton("Button2");
objButtonTwo.setPreferredSize(new Dimension(60,40));
//buttonTestPanel.add(objButtonTwo);
addComp(objButtonTwo,UIBButtonTestGridBagConstraints,buttonTestPanel,1,2,1,GridBagConstraints.WEST);

contentPane.add(buttonTestPanel,BorderLayout.NORTH);

setVisible(true);
}//Constructor ends here


public void addComp(Component comp,GridBagConstraints gridBagConstrain, JPanel panel,int ngridx,int ngridy,
int ngridwd,int nControlAnchor)
{

gridBagConstrain.fill=GridBagConstraints.NONE;
gridBagConstrain.gridx=ngridx;
gridBagConstrain.gridy=ngridy;
gridBagConstrain.gridwidth=ngridwd;
//gridBagConstrain.weighty = 1.0;
//gridBagConstrain.weightx = 1.0;
//gridBagConstrain.insets.top=1;
//gridBagConstrain.insets.right=1;
//gridBagConstrain.insets.left=1;
//gridBagConstrain.insets.bottom=1;
gridBagConstrain.anchor=nControlAnchor;
panel.add(comp,gridBagConstrain);
}

public static void main(String args[])
{
UIBButtonTest objUIBButtonTest = new UIBButtonTest("",false);

}
}
Regards
Narayan
 
 
subject: Gridag-Layout problem in motif look and feel.
 
Threads others viewed
GridBagLayout... Components always centered vertically?
Problem displaying JTable inside a JScrollPane
Is this really where actionlistener should go?
Please help me with this grid bag layout!!
basic concept for swing
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com