• Post Reply Bookmark Topic Watch Topic
  • New Topic

Gridag-Layout problem in motif look and feel.  RSS feed

 
nretharekar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!