Results 1 to 7 of 7
  1. #1
    dejos456 is offline Member
    Join Date
    Nov 2009
    Posts
    18
    Rep Power
    0

    Default Minimize and maximize GUI

    Hi,
    I made a GUI with netbeans. When i run my code i get a window with the 3 Windows buttons in the top right corner : minimize maximize and close (like any other program).

    I made a jMenubar that contains the menuitems minimize and maximize.
    I created actionevents for those menuitems but i can't find working code to put there. For the minimizing i tried :

    Java Code:
    private void MinimaliserenActionPerformed(java.awt.event.ActionEvent evt) {                                              
           texteditorUI.setExtendedState(JFrame.ICONIFIED);
    }
    But i get the error: non-static method setExtendedState(int) cannot be referenced from a static context.

    Does anybody know another method to minimize and maximize my GUI?

  2. #2
    dejos456 is offline Member
    Join Date
    Nov 2009
    Posts
    18
    Rep Power
    0

    Default

    Any ideas?

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Solve the error and the code should work. The error message tell you the problem. If you are using static methods then your GUI is poorly designed. The only static method in the code should be the main(...) method. You need access to the "frame" in order to invoke the method. You should be able to use the SwingUtilities.windowForComponent() method to find the frame that the menubar has been added to.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Your problem isn't that you're calling the wrong method, your problem is that you don't appear to be calling it on a viable JFrame object (I think that you're calling the method on the class name). So you need a reference to the current JFrame, and how you do this will depend on your code which unfortunately, we can't see.

  5. #5
    unideal is offline Member
    Join Date
    Dec 2009
    Posts
    8
    Rep Power
    0

    Default

    Create new JFrame object like

    Java Code:
    JFrame frame = new JFrame("My Java example");

    And then you can call it's setExtendedState like

    Java Code:
    // Minimized window
    frame.setExtendedState(frame.ICONIFIED);
    // Maximize window
    frame.setExtendedState(frame.MAXIMIZED_BOTH);

    I may be wrong though, but that has worked correctly for me. Correct me if I'm wrong.

  6. #6
    dejos456 is offline Member
    Join Date
    Nov 2009
    Posts
    18
    Rep Power
    0

    Default

    I created my program with the GUI editor in netbeans.

    when i look at the left side of netbeans in the Members View (it displays all used menu's etc...) i see texteditorUI:: JFrame, so i thought that was the correct JFrame?

    When i look in the generated code by the GUI editor there is no declaration of a JFrame like unideal said.

    I used the search function, and there is only 1 JFrame in my whole code:

    Java Code:
    package my.texteditorUI;
    import java.io.*;
    import java.awt.print.PrinterException;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import java.awt.event.KeyEvent;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.JFrame.*;
    import javax.swing.event.UndoableEditEvent;
    import javax.swing.event.UndoableEditListener;
    import javax.swing.undo.CannotUndoException;
    import javax.swing.undo.UndoManager;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.BorderLayout;
    
    public class texteditorUI extends javax.swing.JFrame {
        /** Creates new form texteditorUI */
    ...... rest of code
    I just started with Java so i'm not that skilled

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    1) So you are in fact trying to call the method on your class, and that's what the compiler is complaining about. Your JFrame is likely the current object or "this". Have you tried calling your method on this? (actually you can just call the method without specifying "this" as it's implied).
    I just started with Java so i'm not that skilled
    2) That's what practice is all about. If you don't mind some unsolicited advice, you may wish to solidify your basic Java knowledge prior to tackling GUI coding, and
    3) When you do start to learn to code with Swing, don't use NetBeans-generated code as it will prevent you from learning the sorts of things that would have prevented this problem from occurring.

Similar Threads

  1. Replies: 6
    Last Post: 11-22-2010, 12:55 PM
  2. how to minimize the code.
    By arunkumarinfo in forum New To Java
    Replies: 6
    Last Post: 02-01-2009, 05:35 PM
  3. Replies: 2
    Last Post: 12-30-2008, 03:10 PM
  4. Not-resizable (J)dialog showing Maximize Menu !!!
    By playwin2 in forum AWT / Swing
    Replies: 7
    Last Post: 09-08-2008, 01:51 AM
  5. Replies: 1
    Last Post: 04-09-2007, 01:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •