Hy ,

I am using netbeans to create an app.
I wanted to eliminate the windows buttons (minimize , maximize , exit) so i could have full control on the exit button , and i used setUndecorated(true) in the PuppetApp.java (main app that netbeans creates).
Now i created a exit button (which does what i want)in the PuppetView.java (which is lunched from PuppetApp.java and PuppetView.java does not have a "main" that creates a JFrame) and i want to create a minimize button and i don`t know how :
I tried :

private void buttonMinimizeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    try{
        PuppetApp.getApplication().getMainView().getFrame().setState(Frame.ICONIFIED);
    }catch(Exception e){
        System.out.println(e);
    }
    //System.exit(0);
}

and many other versions of it but still no result.
Can anybody help me?

Sorry, I can not understand your problem. Can you post a small program the will compile and execute and demonstrate your problem?

Your application must have at least one class that has the public static void main method in it. That method should start the application by creating other classes as needed.

Sorry for posting that much code .
This is in CaminApp.java

public static void main(String[] args) {
        launch(CaminApp.class, args);
    }
@Override protected void startup() {
        CaminView myFrame = new CaminView(this);
        myFrame.getFrame().setSize(1200,700);
        //setUndecorated(true);
        myFrame.getFrame().setUndecorated(true);
        
        myFrame.getFrame().setVisible(true);
        // Get the size of the screen
        
        //myFrame.getComponent().setb
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        // Determine the new location of the window
        int w = myFrame.getFrame().getSize().width;
        int h = myFrame.getFrame().getSize().height;
        int x =  (dim.width-w)/2;
        int y = ((dim.height-h)/2)-30;
        // Move the window
        myFrame.getFrame().setLocation(x, y);

And from the CaminApp.java it lunches CaminView.java that does not have a main , i sware.

package camin;
import .........
import ........

public class CaminView extends FrameView{
    public CaminView(SingleFrameApplication app) {
        super(app);
        
        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = CaminApp.getApplication().getMainFrame();
            
            aboutBox = new CaminAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        CaminApp.getApplication().show(aboutBox);
    }
    
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = CaminView.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        loginButton = new javax.swing.JLabel();
        buttonMinimize = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(camin.CaminApp.class).getContext().getResourceMap(CaminView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        mainPanel.setName("mainPanel"); // NOI18N

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel1MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel1MouseExited(evt);
            }
        });

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, resourceMap.getColor("jPanel1.border.highlightOuterColor"), resourceMap.getColor("jPanel1.border.highlightInnerColor"), resourceMap.getColor("jPanel1.border.shadowOuterColor"), resourceMap.getColor("jPanel1.border.shadowInnerColor"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel2.setIcon(resourceMap.getIcon("jLabel2.icon")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextField1.setFont(resourceMap.getFont("textNumeLogin.font")); // NOI18N
        jTextField1.setText(resourceMap.getString("textNumeLogin.text")); // NOI18N
        jTextField1.setToolTipText(resourceMap.getString("textNumeLogin.toolTipText")); // NOI18N
        jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextField1.setName("textNumeLogin"); // NOI18N
        jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField1MouseClicked(evt);
            }
        });
        jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField1FocusLost(evt);
            }
        });

        jPasswordField1.setFont(resourceMap.getFont("jPasswordField1.font")); // NOI18N
        jPasswordField1.setText(resourceMap.getString("jPasswordField1.text")); // NOI18N
        jPasswordField1.setName("jPasswordField1"); // NOI18N
        jPasswordField1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPasswordField1MouseClicked(evt);
            }
        });
        jPasswordField1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jPasswordField1FocusLost(evt);
            }
        });

        loginButton.setForeground(resourceMap.getColor("loginButton.foreground")); // NOI18N
        loginButton.setIcon(resourceMap.getIcon("loginButton.icon")); // NOI18N
        loginButton.setText(resourceMap.getString("loginButton.text")); // NOI18N
        loginButton.setName("loginButton"); // NOI18N
        loginButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                loginButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                loginButtonMouseExited(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPasswordField1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
                    .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap(64, Short.MAX_VALUE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(51, 51, 51))
        );

        buttonMinimize.setIcon(resourceMap.getIcon("buttonMinimize.icon")); // NOI18N
        buttonMinimize.setText(resourceMap.getString("buttonMinimize.text")); // NOI18N
        buttonMinimize.setName("buttonMinimize"); // NOI18N
        buttonMinimize.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonMinimizeMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                buttonMinimizeMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                buttonMinimizeMouseExited(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(1120, Short.MAX_VALUE)
                .addComponent(buttonMinimize, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(333, 333, 333)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(343, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(buttonMinimize, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE))
                .addGap(184, 184, 184)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(213, Short.MAX_VALUE))
        );

        setComponent(mainPanel);
    }// </editor-fold>
private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {                                     
// TODO add your handling code here:
        System.exit(0);
}                                    

private void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {                                     
// TODO add your handling code here:
    jLabel1.setIcon(createImageIcon("images/buttonExitPressed.png")); 
}                                    

private void jLabel1MouseExited(java.awt.event.MouseEvent evt) {                                    
// TODO add your handling code here:
    jLabel1.setIcon(createImageIcon("images/buttonExit.png"));
}                                   

private void loginButtonMouseEntered(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    loginButton.setIcon(createImageIcon("images/login.png")); 
}

private void loginButtonMouseExited(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    loginButton.setIcon(createImageIcon("images/loginUnpressed.png"));
}

private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    if(jTextField1.getText().equals("Utilizator")){
        jTextField1.setText("");
    }       
}

private void jPasswordField1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    if(jPasswordField1.getText().equals("Parola")){
        jPasswordField1.setText("");
    } 
    
}

private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
    if(jTextField1.getText().equals("")){
        jTextField1.setText("Utilizator");
    } 
}

private void jPasswordField1FocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
    if(jPasswordField1.getText().equals("")){
        jPasswordField1.setText("Parola");
    } 
}

private void buttonMinimizeMouseEntered(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    buttonMinimize.setIcon(createImageIcon("images/minimizePressed.png"));
}

private void buttonMinimizeMouseExited(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    buttonMinimize.setIcon(createImageIcon("images/minimize.png"));
}

private void buttonMinimizeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    
    //System.exit(0);
}

    // Variables declaration - do not modify
    private javax.swing.JLabel buttonMinimize;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JLabel loginButton;
    private javax.swing.JPanel mainPanel;
    // End of variables declaration

  

    private JDialog aboutBox;
}

Edited 5 Years Ago by nsyncpilu: n/a

Can you post a small program the will compile and execute and demonstrate your problem?
You've posted three pieces of code. The first two won't compile.

I don't know how I'd compile and execute with what you have posted.

Edited 5 Years Ago by NormR1: n/a

This is the exact app , you have the built in DIST folder

Edited 5 Years Ago by nsyncpilu: n/a

Sorry, I want a smaller program that shows the problem. Is the link you just posted to a smaller program? Somehow I doubt it. Anyways, I have no software that will open a .rar file.

1) I think that you have look at WindowListener, very simple example for plain vanilla Swing here

2) don't use Netbeans or any Built-in GUI wrapper, learn plain vanilla Swing, because lots of methods (talking anout fun from coding and clear head) are depreciated or not implemented in these Frameworks (based on swing & AWT), i know that's so easy to drag&drop Components from palette, but then to set any basic methods/properties equals Horror :-)

3) Java Desktop Aplication is long time out-dated, and is too hard to find someone who can remember this Framework

Edited 5 Years Ago by mKorbel: n/a

Sorry but i can`t make a smaller version of it and it is to much code to post it here.
Thanks anyway.

If anybody else sees the thread. My main question is how do i get minimized the app.
I`m developing in NetBeans (desktop application),CaminApp.java lunches CaminView.java that does not contain a "main" and on click event on a button to minimize the app.

Thanks[code listed up] and on click event on a button to minimize the app.


Thanks

@NormR1 these code are Bubbles generated by Framework, your same code in Swing will be up to 40-50 codelines :-)

how do i get minimized the app.

THis code works for me:
setState(Frame.ICONIFIED);

You need access to the class that has a reference to the frame you want to minimize.

package camin;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.*;

/**
 * The main class of the application.
 */
public class CaminApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        CaminView myFrame = new CaminView(this);
        myFrame.getFrame().setSize(1200,700);
        //setUndecorated(true);
        myFrame.getFrame().setUndecorated(true);
        
        myFrame.getFrame().setVisible(true);
        // Get the size of the screen
        
        //myFrame.getComponent().setb
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        // Determine the new location of the window
        int w = myFrame.getFrame().getSize().width;
        int h = myFrame.getFrame().getSize().height;
        int x =  (dim.width-w)/2;
        int y = ((dim.height-h)/2)-30;
        // Move the window
        myFrame.getFrame().setLocation(x, y);
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of CaminApp
     */
    public static CaminApp getApplication() {
        return Application.getInstance(CaminApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(CaminApp.class, args);
    }
}

Edited 5 Years Ago by nsyncpilu: n/a

Tried this and worked.

private void buttonMinimizeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
    //CaminView.class.getSuperclass().
    //CaminView.
    try{
    //SingleFrameApplication.getInstance().getContext().getApplication().hide(this);
     ((JFrame)buttonMinimize.getTopLevelAncestor()).setState ( JFrame.ICONIFIED );
    }catch(Exception e){}
}

I`m sorry because i wasted your time.
Thanks,
Bye

This question has already been answered. Start a new discussion instead.