We have no idea what LayoutManager you are using or how you added the components to the GUI, so no we don't know whats happening.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.
here is the class that was giving me trouble. i've made it execuatable for this example. I found the problem: I was using the UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ) and i'm guessing it was causing the components to missalign. Can someone help fix it?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class LoginFrame
{
private static final long serialVersionUID = 1L;
private String userName;
private char[] password;
public String getUserName(){
return userName;
}
public char[] getPassword(){
return password;
}
private final int textFieldSize = 18;
public boolean okButtonClicked;
public JDialog loginDialogWindow;
JTextField inUserName;
JPasswordField inPwdField;
public LoginFrame()
{
loginDialogWindow = new JDialog((JFrame)null, "Login");
Container c = loginDialogWindow.getContentPane();
c.setLayout( new BoxLayout(c, BoxLayout.Y_AXIS) );
JPanel inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inUserName = new JTextField(textFieldSize);
inputPanel.add( new JLabel("User Name") );
inputPanel.add( inUserName );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inputPanel.add( new JLabel("Password") );
inPwdField = new JPasswordField(textFieldSize);
inputPanel.add( inPwdField );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
JButton okButton = new JButton("OK");
inputPanel.add(okButton);
JButton cancelButton = new JButton("CANCEL");
inputPanel.add(cancelButton);
c.add(inputPanel);
loginDialogWindow.setDefaultCloseOperation( JDialog.DO_NOTHING_ON_CLOSE );
//loginDialogWindow.setResizable(false);
loginDialogWindow.setSize(250,165);
}
public void setDialogLocation( int parentWidth, int parentHeight, int parentX, int parentY )
{
loginDialogWindow.setLocation(
( parentWidth-loginDialogWindow.getWidth() )/2+parentX,
( parentHeight-loginDialogWindow.getHeight() )/2+parentY );
}
public void showLoginDialog()
{
loginDialogWindow.setVisible(true);
}
public void setUserNamePassword( ActionEvent e )
{
userName = inUserName.getText();
password = inPwdField.getPassword();
okButtonClicked = true;
loginDialogWindow.setVisible(false);
}
public void onCancelButtonClick( ActionEvent e )
{
userName = null;
password = null;
okButtonClicked = false;
loginDialogWindow.setVisible(false);
}
public static void main( String[] args )
{
new LoginFrame().showLoginDialog();
}
}
OK...i'm using a BoxLayout on Y_AXIS to add JPanels to a Container. Each JPanel is set to FlowLayout. When I use
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ); and get the native look and feel..you'll notice that the JPasswordField is wider then the JTextField. I don't know what could be causing this. Below is an executable program. If you are using windows xp...you should see the problem. If I don't sepecifiy the LookAndFeel...both the JTextField and JPasswordField look the same. Here is the program
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginFrame
{
private final int textFieldSize = 18;
public JDialog loginDialogWindow;
JTextField inUserName;
JPasswordField inPwdField;
public LoginFrame()
{
loginDialogWindow = new JDialog((JFrame)null, "Login");
Container c = loginDialogWindow.getContentPane();
c.setLayout( new BoxLayout(c, BoxLayout.Y_AXIS) );
JPanel inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inUserName = new JTextField(textFieldSize);
inputPanel.add( new JLabel("User Name") );
inputPanel.add( inUserName );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inputPanel.add( new JLabel("Password") );
inPwdField = new JPasswordField(textFieldSize);
inputPanel.add( inPwdField );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
JButton okButton = new JButton("OK");
inputPanel.add(okButton);
JButton cancelButton = new JButton("CANCEL");
inputPanel.add(cancelButton);
c.add(inputPanel);
loginDialogWindow.setDefaultCloseOperation( JDialog.EXIT_ON_CLOSE );
loginDialogWindow.setResizable(false);
loginDialogWindow.setSize(250,165);
}
public void showLoginDialog()
{
loginDialogWindow.setVisible(true);
}
public static void main( String[] args )
{
try
{
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
}
catch( Exception e )
{
e.printStackTrace();
}
new LoginFrame().showLoginDialog();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginFrame
{
private final int textFieldSize = 18;
public JDialog loginDialogWindow;
JTextField inUserName;
JPasswordField inPwdField;
public LoginFrame()
{
loginDialogWindow = new JDialog((JFrame)null, "Login");
Container c = loginDialogWindow.getContentPane();
c.setLayout( new BoxLayout(c, BoxLayout.Y_AXIS) );
JPanel inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inUserName = new JTextField(textFieldSize);
inputPanel.add( new JLabel("User Name") );
inputPanel.add( inUserName );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
inputPanel.add( new JLabel("Password") );
inPwdField = new JPasswordField(textFieldSize);
inputPanel.add( inPwdField );
c.add( inputPanel );
inputPanel = new JPanel();
inputPanel.setLayout( new FlowLayout() );
JButton okButton = new JButton("OK");
inputPanel.add(okButton);
JButton cancelButton = new JButton("CANCEL");
inputPanel.add(cancelButton);
c.add(inputPanel);
loginDialogWindow.setDefaultCloseOperation(
JDialog.EXIT_ON_CLOSE );
loginDialogWindow.setResizable(false);
loginDialogWindow.setSize(250,165);
}
public void showLoginDialog()
{
loginDialogWindow.setVisible(true);
}
public static void main( String[] args )
{
try
{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName() );
}
catch( Exception e )
{
e.printStackTrace();
}
new LoginFrame().showLoginDialog();
}
}