can someone give me some hints?
I am trying to build a login interface. it maybe seems very easy to you guys. But I have had so many questions,because I am not only new to swing but also new to java. :( ok, shut up. here are my questions:
1. why the interface always pops up at left corner of the screen when I run it?
2.Can I make it appears in the middle of the screen?
3.should I pre-set the size of the interface and its location as well?
4.I just want to build a simple login interface, like the one we will see when we turn on our computer. But I have problem to make the label and textField stay nicely on the screen. Their size change when I enlarge the login interface. so, which layout manager I should use?
Thanks a lot and a lot!
Sarah
[759 byte] By [
sarah.xiaa] at [2007-10-2 11:05:22]

are you using JDialog/JOptionPane?It will center on the parent component if you pass it in as parameter in the appropriate method.
1) the default location is (0, 0).
2) dialog.setLocationRelativeTo( null );
3) No. build your components and then use dialog.pack() so the components will sized at their preferred sizes.
4) Use a JDialog and use setResizable( false );
In two of your previous postings you've be given a link to the Swing tutorial. There are plenty of examples in the tutorial to cover these basic questions that you are asking. You can download the tutorial from here:
http://java.sun.com/docs/books/tutorial/
So download it, read it and execute the example programs.
Given that you also have a history of asking questions and never bothering to take the time to thank people for their help I suspect you won't be getting much help in the future, so it will be even more important for you to read the tutorial.
> are you using JDialog/JOptionPane?
> It will center on the parent component if you pass it
> in as parameter in the appropriate method.
Thank you for your reply.
I am using normal JPane.
Is it bette to use JOptionPane than use JPane for login interface?
Thank you Camickr.
I apologize that I didn't say thank you to people trying to help me in my past post although I appreciated inside.
I have looked at the tutorial examples you gave to me last time. I think I will have a further look at them.
Hope I am still allowed to ask for help here.:(
Thanks for everyone trying to help me.
Sarah.
a useful link i found : http://java.sun.com/products/jlf/ed2/book/index.html
hai,
I m also working out in the same login interface ..So try my suggestions
In order to get the login interface in the middle...use GRIDBAGLAYOUT MANAGER..its gets ur interface in the center....
this manager had Constraints gridx,gridy and so and also search for
HOW TO USE GRIDBAGLAYOUT.....in search engine its gets u clear idea...
And also for the login button, cancel button use some other panel..
Dont't use the same panel(gridbag layout....)
Reply me soon after try my suggestion
Shanthy
Hi Shanthy, thanks for your suggestion.
I realized that GridBagLayout is the best for laying out label/text field pair,so I tried it. It is a little bit hard to use this layout manager properly. I am working on it. Did some experiment, seems work. But still don't know how to make the window pops up in the middle of the screen.
Regards.
sarah.
> But still don't know how to make the window pops up in the middle of the screenThen you obviously haven't read the replies you've been give very closely.
> > But still don't know how to make the window pops
> up in the middle of the screen
>
> Then you obviously haven't read the replies you've
> been give very closely.
I think I should say: shanthy, I haven't tried the method Camickr told me, so I haven't found how to make the window pops up in the middle of the screen.
Camickr:
thanks your help. The window pops up in the middle of the screen eventually.
There is another basic question:
The login interface I am building will be called by main application. Right now I used JFrame instead of JDialog and the interface looks all right. i am just worried that will there be some problems when it is intergated into main application?
Thanks.
> There is another basic question:
> The login interface I am building will be called by
> main application. Right now I used JFrame instead of
> JDialog and the interface looks all right. i am just
> worried that will there be some problems when it is
> intergated into main application?
>
There shouldn't be any problems. The layout will look the same if you use a JDialog instead of a JFrame.
> There shouldn't be any problems. The layout will look> the same if you use a JDialog instead of a JFrame.Thanks mate~
Another question:On the left-top corner of every Java swing frame, there is a coffee cup. How can I change the icon?
JFrame frame = ...Image image = ...frame.setIconImage(image);Btw, this is covered in the tutorial: http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
> > JFrame frame = ...
> Image image = ...
> frame.setIconImage(image);
>
> Btw, this is covered in the tutorial:
>
> http://java.sun.com/docs/books/tutorial/uiswing/compon
> ents/frame.html
oh,yes. Didn't read carefully. Thanks.
> > JFrame frame = ...> Image image = ...> frame.setIconImage(image);> > Btw, this is covered in the tutorial:> > http://java.sun.com/docs/books/tutorial/uiswing/compon> ents/frame.htmlthanks.
thanks for the tip (2) camickr, that was what am looking for.
I actually wrote a small code to do the center thing. I think this is due to my VB background :)
protected void centerDialog() {
Dimension screenSize = this.getToolkit().getScreenSize();
Dimension size = this.getSize();
screenSize.height = screenSize.height;
screenSize.width = screenSize.width;
size.height = size.height;
size.width = size.width;
int y = (screenSize.height - size.height) / 2;
int x = (screenSize.width - size.width) / 2;
this.setLocation(x, y);
}
> 1) the default location is (0, 0).
> 2) dialog.setLocationRelativeTo( null );
> 3) No. build your components and then use
> dialog.pack() so the components will sized at their
> preferred sizes.
> 4) Use a JDialog and use setResizable( false );
>
> In two of your previous postings you've be given a
> link to the Swing tutorial. There are plenty of
> examples in the tutorial to cover these basic
> questions that you are asking. You can download the
> tutorial from here:
>
> http://java.sun.com/docs/books/tutorial/
>
> So download it, read it and execute the example
> programs.
>
> Given that you also have a history of asking
> questions and never bothering to take the time to
> thank people for their help I suspect you won't be
> getting much help in the future, so it will be even
> more important for you to read the tutorial.
