Reputation: 571
I'm developing Java Desktop Application in NetBeans IDE. I want to show the login screen in JFrame
with small size. Then after getting login i want to extend JFrame
to full screen with other panels.The problem is its showing once properly and from the next time it used to show the login screen with full screen.How can i avoid it? I'm placing different panels on the same frame.
While login
this.getFrame().setExtendedState(Frame.NORMAL);
this.getFrame().setSize(360, 233);
this.getFrame().setResizable(false);
After login
this.getFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
Upvotes: 1
Views: 16366
Reputation: 11
Put in your constructor, after the initComponent() function a simple piece's code
initComponents();/*Function automated*/
setMinimumSize(new Dimension(700,400).getSize());
setExtendedState(MAXIMIZED_BOTH);/*To see your application starts maximized!*/
Upvotes: 1
Reputation: 4250
Edit after chat;
According to scenario; External desktop application hold, remember and set frames size's to last settings. So inner panel must get external main frame from desktop application and set size and location settings after application runs after internal code runs.
There is no more things I can do about codes without having whole project :)
Previous answers; For an alternative, you may use JDialog to login else next time when you show login screen, reverse what you do when setting fullscreen.
Some code samples helps us to answer your question better.
Edit 2: he next time before login screen did you use;
this.getFrame().setExtendedState(Frame.NORMAL);
Edit 3: Code Sample
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class MyFrame extends JFrame implements MouseListener {
/**
* @param args
*/
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setVisible(true);
frame.setSize(200, 200);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.addMouseListener(frame);
}
@Override
public void mouseClicked(MouseEvent e) {
if(this.getExtendedState() == JFrame.MAXIMIZED_BOTH){
this.setExtendedState(JFrame.NORMAL);
}
else{
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
Upvotes: 2
Reputation: 168815
I want to show the login screen in
JFrame
with small size. Then after getting login I want to extendJFrame
to full screen with other panels.
Show the frame at the full size, and make it the owner of a modal JDialog
or JOptionPane
that shows the login details. If the login fails and the user chooses to cancel instead of try again, exit the app.
If I design a new
JDialog
for login then how can I show it initially?
JFrame f = this.getFrame();
JDialog loginDialog = new JDialog(f,"Login",true);
loginDialog.add(loginPanel);
loginDialog.pack();
f.setExtendedState(Frame.MAXIMIZED_BOTH)
f.setVisible(true);
loginDialog.setLocationRelativeTo(f);
loginDialog.setVisible(true);
Upvotes: 2