Reputation: 31
Is there a way to center-align components vertically using the FlowLayout
layout manager only? or would I need to use a different layout manager?
I have to give constant values of horizontal seperation to get elements on different lines, Is there a way to dynamically do it?
Frame frame = new Frame();
frame.setLayout(new FlowLayout(FlowLayout.CENTER,500,40)); // i have to give a constant value for horizontal separation here
frame.setSize(450,270);
frame.setVIsible(true);
What I want it to look like:
The complete main method of my program (if needed)
public static void main(String args[]) throws IOException // frame is an instance varible
{
secure ob=new secure();
Font font=new Font("SanSerif",Font.PLAIN,14);
ob.frame.setLayout(new FlowLayout(FlowLayout.CENTER,500,40));
ob.frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent windowEvent)
{
System.exit(0);
}
});
Button b=new Button("Enter");
TextField text = new TextField(10);
ob.l.setSize(50,20);
b.setSize(50,70);
ob.frame.add(ob.l);
ob.frame.add(text);
ob.frame.add(b);
ob.frame.setAlwaysOnTop(true);
ob.frame.setTitle("Password Check");
ob.frame.setSize(450,270);
ob.frame.setLocationRelativeTo(null);
ob.frame.setVisible(true);
text.setEchoChar('*');
ob.l.setAlignment(Label.CENTER);
ob.l.setFont(font);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String pass1 = text.getText();
pass1=pass1.trim();
try
{
ob.check(pass1);
text.setText("");
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
});
}
I am new and have been researching on this for the past few days only, so may have missed out on essential information. Do correct me if I am wrong. :)
Upvotes: 1
Views: 179