JFrame Resizing in Desktop Application - NetBeans

混江龙づ霸主 提交于 2019-12-11 05:58:19

问题


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


回答1:


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



回答2:


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

    }

}



回答3:


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


来源:https://stackoverflow.com/questions/8265548/jframe-resizing-in-desktop-application-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!