1

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

bharath
  • 14,283
  • 16
  • 57
  • 95
Mukthi
  • 561
  • 4
  • 13
  • 35
  • resize it when you show the login screen? Just to get this straight: You show a `JFrame` with a size of let's say `200x200` then you use that `JFrame` to display something else and resize it to fullscreen. Now when you show the login in the same `JFrame` you want it to resize back to `200x200`, right? If the `resize()` doesn't work maybe you should call `setExtendedState(Frame.NORMAL)` before resizing – PeterT Nov 25 '11 at 06:43
  • im using the main JFrame to show the login details tha im placing new jpanel which are of different size.Initially i designed my JFrame of login form size. – Mukthi Nov 25 '11 at 07:01

3 Answers3

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

    }

}
Yusuf K.
  • 4,195
  • 1
  • 33
  • 69
  • I tried this too.But after login i cant make the jframe to full screen. – Mukthi Nov 25 '11 at 07:25
  • I have no problem with above sample code in my answer. Every click on frame switches between maximized and normal size of frame – Yusuf K. Nov 25 '11 at 07:40
  • ya...But but im replacing the Jframes panel after login.Is it will be the proble? – Mukthi Nov 25 '11 at 07:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5332/discussion-between-ykartal-and-sakthibalaji) – Yusuf K. Nov 25 '11 at 07:55
2

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);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

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!*/
Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202