简体   繁体   中英

JFrame Resizing in Desktop Application - NetBeans

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);

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

    }

}

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.

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);

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!*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM