Results 1 to 2 of 2
- 11-16-2011, 09:30 PM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
centering/sizing fields on a panel
I am having a hard time getting my text field and password fields to size correctly and to appear in the middle of the screen. Any help?
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LoginScreen extends JFrame { public static void main(String[] args) { new LoginScreen(); } public LoginScreen() { super("Log-In"); this.setDefaultCloseOperation(super.EXIT_ON_CLOSE); Container content = getContentPane(); content.setPreferredSize(new Dimension(400,200)); content.setBackground(Color.black); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(Box.createRigidArea(new Dimension(0,100))); JFormattedTextField user = new JFormattedTextField(); JPasswordField pword = new JPasswordField(); content.add(user, BorderLayout.PAGE_START); user.setSize(5,2); content.add(Box.createRigidArea(new Dimension(0,30))); content.add(pword, BorderLayout.PAGE_START); pword.setSize(5,2); pack(); setVisible(true); } }
- 11-20-2011, 10:01 AM #2
Member
- Join Date
- Jul 2011
- Posts
- 27
- Rep Power
- 0
Re: centering/sizing fields on a panel
Hi,
first I would put this after setDefaultCloseOperation():
so your JFrame will be placed in the middle of you screen.Java Code:this.setLocationRelativeTo(null);
And for the textfield itself I would use the GridLayout(int rows,int columns);
In that way you don't have to place the size. All component will have the same size and would be allign.
Similar Threads
-
JTable sizing issues
By Timmins in forum AWT / SwingReplies: 6Last Post: 04-02-2011, 02:40 AM -
Panel sizing
By sjs in forum AWT / SwingReplies: 5Last Post: 10-11-2010, 03:13 AM -
component centering
By BigBear in forum AWT / SwingReplies: 3Last Post: 01-24-2010, 11:48 PM -
Trouble with Buffer Sizing
By Jeff in forum New To JavaReplies: 3Last Post: 02-07-2008, 01:43 PM -
Help needed with sizing components
By adlb1300 in forum New To JavaReplies: 2Last Post: 11-20-2007, 04:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks