Cant dispose a JFrame

hi
i'm having a problem with jFrame disposion. i have a login JDialog, that launches JFrame. After logoff - the same JDialog appears. And when i call JFrame again - i get 2 flashing frames, that are disabling/enabling one another, and swithing from one to another. after some accurate clicks in taskbar - forms stop flicker, but i still have 2 of them.
then you may try to logoff and login again from one of them - and guess what - i get 4 flikering frames. dammit.
how to completely dispose Frame?
tryed everything in forums with keyword "dispose". no luck.
many many many thanx.

I presume your are calling frame.dispose() from your Dialog window, and not trying to be clever by calling it in your finalizer? Additionally, you could setframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Similar Messages

  • Disposing a jframe, and freeing up memory

    Greetings,
    I hope this is the proper forum for memory issues.
    I have an enterprise database reporting desktop application that I am developing. The GUI application reports on a huge set of data that results in the app taking up to 125 MB worth of memory when fully loaded. There are moments in using the application that all of the data will need to be refreshed entirely, and the JFrame that reports it be reloaded in the process.
    I am wondering how to dispose the JFrame and release all of the data associated with it. I use NetBeans to develop my GUI, and so all of the data that is needed for the JFrame is a class variable of the JFrame (so the data can be accessed as it is needed). But, when the frame is disposed, I no longer need anything associated with the JFrame that gets disposed. The Javadoc for Window.dispose() seems to imply that not all of the resources will be released and GC'd when you call dispose, because it says "The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show." which to me says that the data is being remembered and not collected by the GC.
    Anyone have any tips for GUIs and memory management? It seems like any GUI app could get pretty large pretty fast if there's no way to release the data associated with the GUI.
    Here's the code I've tested that doesn't seem to be releasing the memory (stress tests of closing and re-opening the window multiple times shows the java.exe process eating more and more memory):
        public void reset(){
            this.dispose();
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new PartsDashboard(partNum, dateFrom, dateTo);
            try{
                this.finalize();
            } catch (Throwable t){
                t.printStackTrace();
        }Thanks in advance.

    Three things you can always count on in life: Death, Taxes, and AndrewThompson64 telling people to post an SSCCE. =)
    Just poking fun.
    Anyways, this problem has gone from probably-should-deal-with-soon to critical issue. Here is the SSCCE to illustrate the problem. NOTE: My client is using Windows and I am using Windows, so how this acts on Linux/Mac isn't important to me. Also, a few of my client's machines are not well equipped (512 MB RAM), so they have agreed to up their hardware a bit.
    But the big problem, on my end, is that disposed windows DO NOT free up resources once disposed. My program is very data-heavy. I have considered grabbing less data from the database but this would mean the program would have to go to the database more often. The ultimate dilemma of time vs space, essentially.
    To explain the SSCCE: There is a main window with a button. If you click the button, it launches another window with a String array that is 500,000 items large (to simulate a lot of data), and a JList to view those strings. Closing the data-heavy child window does not free up the memory that it uses, and if you launch a bunch of the child windows in the same program instance (close each child before launching a new one) then you will see the amount of memory piling up.
    Am I doing something wrong? Has anyone else experienced similar problems? Does anyone have suggestions? Thank you.
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    * @author Ryan
    public class MemoryLeak {
        public static void main(String[] args) {
            // Launch Base Frame
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new BaseFrame().setVisible(true);
    class BaseFrame extends JFrame{
        public BaseFrame() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setPreferredSize(new Dimension(300,300));
            JPanel panel = new JPanel();
            panel.setLayout(new FlowLayout(FlowLayout.CENTER, 150, 5));
            JButton button = new JButton("Launch Data-Heavy Child");
            // JButton will launch Child Frame
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            // Notice no references to ChildFrame, period.
                            new ChildFrame().setVisible(true);
            panel.add(button);
            add(panel);
            pack();
    class ChildFrame extends JFrame{
        public ChildFrame() {
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setPreferredSize(new Dimension(300,600));
            JPanel panel = new JPanel();
            panel.setLayout(new FlowLayout());
            // Simulate lots of data.
            String[] dataArr = new String[500000];
            for(int i = 0; i < dataArr.length; i++) {
                dataArr[i] = "This is # " + i;
            // Something to display the data.
            JList list = new JList(dataArr);
            JScrollPane scrollPane = new JScrollPane(list);
            scrollPane.setPreferredSize(new Dimension(200, 550));
            panel.add(scrollPane);
            add(panel);
            pack();
    }

  • Dispose when jframe is minimised

    hey peepz...
    i want the jframe to be disposed instead of minimised when another jframe appears. i am not sure how to do it because the latter jframe or the 2nd jframe belongs to the same class but is created by different constructor. so it is something like constructor2 is being called upon when something is done in constructor1.
    how do we go around doing that?
    thanks
    farah k.

    public class whatever1 extends jpanel {
    whatever2 panel1;
    whatever3 panel2;
    whatever1 (String variable1, String variable 2) {
    whatever2 panel1 = new whatever2(variable1, panel2);
    whatever3 panel2 = new whatever3( variable2, panel1);
    add (jpanel1);
    add (jpanel2);
    whatever1 (String variable1, String variable 2, String variable3) {
    whatever2 panel1 = new whatever2(variable3, panel2);
    whatever3 panel2 = new whatever3( test, panel1);
    add (jpanel1);
    add (jpanel2);
    class whatever2 extends jpanel {
    JButton action1;
    String variable1, variable3, variable4;
    jpanel(String name, whatever3 jpanel2) {
    action1.addActionListener(
    public void actionPerformed(ActionEvent e) {
         dispose(); /*i want to dispose this the first frame which was generated by the first constructor but there is no such function within jpanel*/
    new whatever1(variable1, variable3, variable4);
    }

  • Getting a JFrame to display  from a JSP, remaining JSP code waits for frame

    Hello,
    I'm new to Java and just started using JSPs. My objective is to call a display window (from a JSP) that shows the user a list of project selections. Once the user has made their selections and clicked a Submit button, the display class captures the selected projects to the request object as an attribute and then closes the window. The next command in the jsp then forwards the request attribute to a controller. I'm having trouble getting the display window to show-the JSP seems to hang and then timeout. Is there code I'm missing to get the JSP to stop processing while it waits for the choices to be made in the JFrame?
    Below is the JSP code and the class I'm calling. I'm seeing all my debug System.out statements but no JFrame pops up. In the JFrame class, the line f.addWindowListener(... does the capture of user selections to the request attribute.
    Any help will be greatly appreciated!!
    JSP:
    <%@ page language="java" contentType="text/html;charset=UTF-8" import="com.plumtree.remote.portlet.*,edu.app.projects.*" %>
    <%
        request.setAttribute("action", "prefDisplay");
        request.setAttribute("orderby", "title");
        ServletContext jc = getServletContext();
        DualListBox dual = new DualListBox(request,(String)jc.getAttribute("db.driver"), (String)jc.getAttribute("db.connectionstring"),"title");
         JFrame f = dual.getFrame();
         f.setVisible(true);//expect code to stop here and display frame, waiting for the user to finish.
            //Debug code that tests if frame is visible at this point -came true though did not see Jframe displayed
         if(f.isShowing()){
         System.out.println("Jframe visible");}
           //Send to ProjectsController
          request.getRequestDispatcher("pc").forward(request, response);%>               ---------------------------------------------------------------------------------------------
    JFrame Class (below)
    -Sets up Frame and corresponding Dialog box
    -Populates Dialog box with options from a database call (for user selection)
    -Should wait for user input - Window close or Submit! to capture selection and dispose of Jframe
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.Frame;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.lang.reflect.InvocationTargetException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.SortedSet;
    import java.util.TreeSet;
    import javax.servlet.http.HttpServletRequest;
    import javax.swing.AbstractListModel;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ListCellRenderer;
    import javax.swing.ListModel;
    public class DualListBox extends JPanel {
      private static final long serialVersionUID = 1L;
      private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
      private static final String ADD_BUTTON_LABEL = "Add >>";
      private static final String REMOVE_BUTTON_LABEL = "<< Remove";
      private static final String DONE_BUTTON_LABEL = "Submit!";
      private static final String DEFAULT_SOURCE_CHOICE_LABEL = "Available Projects";
      private static final String DEFAULT_DEST_CHOICE_LABEL = "Your Selections";
      private String orderby, mydriver, connectionString;
      private JLabel sourceLabel;
      private JList sourceList;
      private SortedListModel sourceListModel;
      private JList destList;
      private String chosenprojects;
      private SortedListModel destListModel;
      private JLabel destLabel;
      private JButton addButton;
      private JButton removeButton;
      private JButton doneButton;
      private DatabaseHelper dh;
      protected HttpServletRequest request;
      protected JFrame f;
      protected JDialog jd;
      public DualListBox(HttpServletRequest req, String driver, String connection, String ordering) {
         System.out.println("In DualList Setup");
        request =req;
         orderby =ordering;
         connectionString = connection;
         mydriver = driver;
         f = new JFrame("Projects List Selector");     
         jd =new JDialog(f,true);
         jd.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         System.out.println("B4 initscreen");
        initScreen();
        System.out.println("After initscreen");
        String[] DBprojects = this.dbCall();
        System.out.println("After DB Call");
        this.addSourceElements( DBprojects );   
        System.out.println("Filled screen");
        jd.getContentPane().add(this, BorderLayout.CENTER);
        //f.getContentPane().add(jd, BorderLayout.CENTER);
        jd.setSize(800, 600);
        System.out.println("OK2");
        jd.setVisible(true);
        System.out.println("OK3");
        Runnable runner = new FrameShower(jd);
        EventQueue.invokeLater(runner);
      public String getSourceChoicesTitle() {
        return sourceLabel.getText();
      public String chosenprojects() {
             return chosenprojects;
      public JFrame getFrame() {
             return f;
      public void setSourceChoicesTitle(String newValue) {
        sourceLabel.setText(newValue);
      public String getDestinationChoicesTitle() {
        return destLabel.getText();
      public void setDestinationChoicesTitle(String newValue) {
        destLabel.setText(newValue);
      public void clearSourceListModel() {
        sourceListModel.clear();
      public void clearDestinationListModel() {
        destListModel.clear();
      public void addSourceElements(ListModel newValue) {
        fillListModel(sourceListModel, newValue);
      public void setSourceElements(ListModel newValue) {
        clearSourceListModel();
        addSourceElements(newValue);
      public void addDestinationElements(ListModel newValue) {
        fillListModel(destListModel, newValue);
      private String[] dbCall(){
             if(dh==null)
                  dh = new DatabaseHelper(mydriver, connectionString);
              PreparedStatement ps = null;
              ResultSet rs = null;
              ArrayList<String>children = new ArrayList<String>();
              ArrayList<String[]>tree =new ArrayList<String[]>();
              if(orderby==null || orderby.equals("")){
                   orderby ="region";
              String query = "select title,id from projects";// order by " + orderby;
              System.out.println(query);
              try {
                   Connection conn =dh.getConnection();
                   ps = conn.prepareStatement(query);
                   rs = ps.executeQuery();
                   while (rs.next()) {
                        children.add(new String(rs.getString(1)));
                        System.out.println(rs.getString(1));
                        tree.add(new String[]{rs.getString(1),rs.getString(2)});
                   request.setAttribute("ResultTree",tree);
                   return (String[])children.toArray(new String[children.size()]);
              } catch (SQLException e) {
                   throw new RuntimeException(e);
              } finally {
                   try {
                        if (null != rs) rs.close();
                   } catch (SQLException e) {
                   try {
                        if (null != ps) ps.close();
                   } catch (SQLException e) {
      private void fillListModel(SortedListModel model, ListModel newValues) {
        int size = newValues.getSize();
        for (int i = 0; i < size; i++) {
          model.add(newValues.getElementAt(i));
      public void addSourceElements(Object newValue[]) {
        fillListModel(sourceListModel, newValue);
      public void setSourceElements(Object newValue[]) {
        clearSourceListModel();
        addSourceElements(newValue);
      public void addDestinationElements(Object newValue[]) {
        fillListModel(destListModel, newValue);
      private void fillListModel(SortedListModel model, Object newValues[]) {
        model.addAll(newValues);
      public Iterator sourceIterator() {
        return sourceListModel.iterator();
      public Iterator destinationIterator() {
        return destListModel.iterator();
      public void setSourceCellRenderer(ListCellRenderer newValue) {
        sourceList.setCellRenderer(newValue);
      public ListCellRenderer getSourceCellRenderer() {
        return sourceList.getCellRenderer();
      public void setDestinationCellRenderer(ListCellRenderer newValue) {
        destList.setCellRenderer(newValue);
      public ListCellRenderer getDestinationCellRenderer() {
        return destList.getCellRenderer();
      public void setVisibleRowCount(int newValue) {
        sourceList.setVisibleRowCount(newValue);
        destList.setVisibleRowCount(newValue);
      public int getVisibleRowCount() {
        return sourceList.getVisibleRowCount();
      public void setSelectionBackground(Color newValue) {
        sourceList.setSelectionBackground(newValue);
        destList.setSelectionBackground(newValue);
      public Color getSelectionBackground() {
        return sourceList.getSelectionBackground();
      public void setSelectionForeground(Color newValue) {
        sourceList.setSelectionForeground(newValue);
        destList.setSelectionForeground(newValue);
      public Color getSelectionForeground() {
        return sourceList.getSelectionForeground();
      public String getProjects(){
           return chosenprojects;
      private void clearSourceSelected() {
        Object selected[] = sourceList.getSelectedValues();
        for (int i = selected.length - 1; i >= 0; --i) {
          sourceListModel.removeElement(selected);
    sourceList.getSelectionModel().clearSelection();
    private void clearDestinationSelected() {
    Object selected[] = destList.getSelectedValues();
    for (int i = selected.length - 1; i >= 0; --i) {
    destListModel.removeElement(selected[i]);
    destList.getSelectionModel().clearSelection();
    private void initScreen() {
    setBorder(BorderFactory.createEtchedBorder());
    setLayout(new GridBagLayout());
    sourceLabel = new JLabel(DEFAULT_SOURCE_CHOICE_LABEL);
    sourceListModel = new SortedListModel();
    sourceList = new JList(sourceListModel);
    add(sourceLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0,
    GridBagConstraints.CENTER, GridBagConstraints.NONE,
    EMPTY_INSETS, 0, 0));
    add(new JScrollPane(sourceList), new GridBagConstraints(0, 1, 1, 5, .5,
    1, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    EMPTY_INSETS, 0, 0));
    addButton = new JButton(ADD_BUTTON_LABEL);
    add(addButton, new GridBagConstraints(1, 2, 1, 2, 0, .25,
    GridBagConstraints.CENTER, GridBagConstraints.NONE,
    EMPTY_INSETS, 0, 0));
    addButton.addActionListener(new AddListener());
    removeButton = new JButton(REMOVE_BUTTON_LABEL);
    add(removeButton, new GridBagConstraints(1, 4, 1, 2, 0, .25,
    GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
    0, 5, 0, 5), 0, 0));
    removeButton.addActionListener(new RemoveListener());
    doneButton = new JButton(DONE_BUTTON_LABEL);
    add(doneButton, new GridBagConstraints(1, 6, 1, 2, 0, .25,
    GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(
    0, 10, 0, 10), 0, 0));
    doneButton.addActionListener(new DoneListener());
    f.addWindowListener(new java.awt.event.WindowAdapter() {
         public void windowClosing(WindowEvent winEvt) {
              //could set to null here to force use of Done button only
         chosenprojects = destList.getSelectedValues().toString();
              request.setAttribute("ProjectIDs", destList.getSelectedValues().toString());
              System.exit(0);
    destLabel = new JLabel(DEFAULT_DEST_CHOICE_LABEL);
    destListModel = new SortedListModel();
    destList = new JList(destListModel);
    add(destLabel, new GridBagConstraints(2, 0, 1, 1, 0, 0,
    GridBagConstraints.CENTER, GridBagConstraints.NONE,
    EMPTY_INSETS, 0, 0));
    add(new JScrollPane(destList), new GridBagConstraints(2, 1, 1, 5, .5,
    1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
    EMPTY_INSETS, 0, 0));
    private class AddListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    Object selected[] = sourceList.getSelectedValues();
    addDestinationElements(selected);
    clearSourceSelected();
    private class RemoveListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    Object selected[] = destList.getSelectedValues();
    addSourceElements(selected);
    clearDestinationSelected();
    private class DoneListener implements ActionListener {
         public void actionPerformed(ActionEvent e) {
         chosenprojects = destList.getSelectedValues().toString();
         request.setAttribute("ProjectIDs", destList.getSelectedValues().toString());
         System.exit(0);      
    class FrameShower implements Runnable {
         final JDialog frame;
         public FrameShower(JDialog frame) {
              this.frame = frame;
         public void run() {
              System.out.println("B4 make visible");
              frame.setVisible(true);          
         System.out.println("Made screen visible");
    class SortedListModel extends AbstractListModel {
    private static final long serialVersionUID = 8777627817685130496L;
    SortedSet model;
    public SortedListModel() {
    model = new TreeSet();
    public int getSize() {
    return model.size();
    public Object getElementAt(int index) {
    return model.toArray()[index];
    public void add(Object element) {
    if (model.add(element)) {
    fireContentsChanged(this, 0, getSize());
    public void addAll(Object elements[]) {
    Collection c = Arrays.asList(elements);
    model.addAll(c);
    fireContentsChanged(this, 0, getSize());
    public void clear() {
    model.clear();
    fireContentsChanged(this, 0, getSize());
    public boolean contains(Object element) {
    return model.contains(element);
    public Object firstElement() {
    return model.first();
    public Iterator iterator() {
    return model.iterator();
    public Object lastElement() {
    return model.last();
    public boolean removeElement(Object element) {
    boolean removed = model.remove(element);
    if (removed) {
    fireContentsChanged(this, 0, getSize());
    return removed;
    }{code}
    Edited by: redm14A on Oct 10, 2007 11:34 AM
    Edited by: redm14A on Oct 10, 2007 11:37 AM
    Edited by: redm14A on Oct 10, 2007 11:40 AM
    Edited by: redm14A on Oct 10, 2007 11:45 AM
    Edited by: redm14A on Oct 10, 2007 11:47 AM

    redm14A wrote:
    Hmm, I was trying to avoid writing an applet. Seems my only other option then is to write a JSP that returns a javascript menu populated by options from a database call. Then I'd have the user click submit to send the options to another JSP that simply sets the request attribute and forwards to the controller. Will this be a sound alternative?
    Edited by: redm14A on Oct 10, 2007 12:29 PMSounds good to me.

  • JFrame displays without its components or settings (please help)

    On clicking a button in an app, due to computational time required, I need to have a message popup that says 'Please Wait', which vanishes on end of needed computation. For this, I have a small working class MsgDiag that simply displays a non-modal titled JFrame showing a message string in a JLabel and an 'ok' in a JButton. This works fine when invoked directly via its own main method as a standalone, but when called from that other application(also a extended JFrame) via button click, it just brings up a blank grey untitled JFrame without the components (JLabel and JButton) or the background color! It does stay up for the required duration and vanishes on disposing its JFrame as expected but why blank w/o components or settings ?
    I also find that though the JFrame component comes up blank grey, if during the computation portion in calling application, if any info/errors are popped up via direct call to a JOptionPane().showMessageDialog(JFrame(),msgString, titleString, msgType), then along with that modal popup (from JOptionPane), the grey JFrame gets correctly drawn with components and background !
    Does this provide any hints ? Since MsgDiag works ok by itself I am puzzled.
    I also tried putting basic code from MsgDiag (creating JFrame, adding its components, setting it visible etc) into the other app directly but same grey blank frame results. Had there been a non-modal JOptionPane I could have tried using it. I use JRE 1.4.2

    Per your suggestion, I tried putting computational part in a different thread. Also tried putting the thread priority for computational thread to lowest.
    In other approach, also tried putting the GUI popup (frame2) in a separate thread with highest priority while lowest priority computational thread executed. But neither approach worked. Still shows frame2 as blank w/o background or components inside while low priority computational thread finished, when frame2 gets disposed as instructed.
    In 1st approach, also tried adding validate() following setSize() as some other posts have suggested but that did not change anything. Any other pointers ?

  • Problem to close a Frame(not) JFrame...

    public void windowClosing(WindowEvent e) {
    System.exit(0);
    I use this method but my frame window is not closing...Plz help

    if u extends JFrame then add this code
      addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e) {
                    if(JOptionPane.showConfirmDialog(null,"Are you sure to  exitt!","Confirmation",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE)==0){
                        dispose();
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        System.exit(0);
                    }else{
                        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            });

  • Help with calling up a JPanel

    I posted a simular problem to this earlier, but got tottally muddled up in what i was writing. I have been stuck on this now for quite a while and its problably really straight forward. Basically i have a class called Meet which extends a JPanel as it is using JTabbedPane and i followed a sun tutorial. Now this JPanel gets added to a JFrame in my code through
           JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);Now this class all works great when run alone. But then in another class which extends a JFrame, one of the buttons should be calling up the above Meet class. So i declared Meet meet; and i created the CreateAtlDatabase_actionPerformed method.
         private void CreateAtlDatabase_actionPerformed()
              meet = new Meet();
                    this.dispose();
              } But everytime this button is pressed, the whole program crashes. I have also tried different ways, for instance i removed the JFrame code from my Meet class and placed it in my CreateAtlDatabase_actionPerformed method, so that the frame is created on request, but then i have problems disposing of the gui in my Meet class. The circle continues. Any advise on what i can do would be great.

    But everytime this button is pressed, the whole program crashes.By this i mean when i press the button, the whole application just freezes, and then after quite a long time my command line displays
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa
    ce
            at javax.swing.plaf.basic.BasicTabbedPaneUI.createScrollButton(BasicTabb
    edPaneUI.java:305)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$ScrollableTabSupport.createB
    uttons(BasicTabbedPaneUI.java:3253)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$ScrollableTabSupport.<init>(
    BasicTabbedPaneUI.java:3238)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.installComponents(BasicTabbe
    dPaneUI.java:258)
            at javax.swing.plaf.basic.BasicTabbedPaneUI.installUI(BasicTabbedPaneUI.
    java:206)
            at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.propertyChange(Basic
    TabbedPaneUI.java:3521)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:339)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:276)
            at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
    port.java:297)
            at java.awt.Component.firePropertyChange(Component.java:7908)
            at javax.swing.JComponent.firePropertyChange(JComponent.java:4454)
            at javax.swing.JTabbedPane.setTabLayoutPolicy(JTabbedPane.java:536)
            at Meet.<init>(Meet.java:264)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)
            at Meet.<init>(Meet.java:268)I then took this code out of my Meet class(class which extends the JPanel)
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);And i place it in the action event of the class that calls up the JPanel.
         private void CreateAtlDatabase_actionPerformed()
            JFrame frame = new JFrame("MEET_dataTable");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(new Meet(), BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
            this.dispose();
              } Now that seems to do the trick, i just wasnt sure if it was allowed. But in doing this another problem is created. In my Meet class, i have a go back button which should return the user to the JFrame gui and dispose of the JPanel gui. But of course you cannot use this.dispose() on a JPanel and i no longer have the JFrame to which the panel is added in this class, which means i cant dispose of its JFrame. I have tried using System.exit(0) but this closes everything, and my last attempt has been
    private void back_actionPerformed() 
            this.getParent().setVisible(false);
            CreateAtlDatabase data = new CreateAtlDatabase();
      Which removes the JPanel but leaves an empty JFrame. Now this is where i am stuck, how can i dispose of this? and of course is the moving of my JFrame to my other class ok?
    cheers

  • Value from JDialog to another class

    Hi:
    I have a trouble with getting my values from a JDialog box to another class.
    Here's what I have:
    This is an ftp application. I have a main frame where if the user selects File->New Connection
    it pops up a Connect dialog box. The connect dialog box has various fields such as profile name, host address, user name, and so on. In addition, there are three buttons, Add, Connect and Cancel.
    After the user types info and clicks Connect, all these information should be sent to the main frame from where it would send the information to another class which would connect to the ftp server.
    I have a class called Profile which is used to wrap these information to be sent to the main frame.
    Now, how can i get this info to the main frame? Here's the code in main frame:
    class MainFrame extends JFrame {
    JMenuItem newconnection = new JMenuItem("New Connection", 'N');
    newconnection.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Profile p = new Profile();
    ConnectDialog con = new ConnectDialog();
    p = con.getProfile();
    makeNewConnection(p); //this is the method i use to make a new connection
    The problem is that by the time i get to the line p = con.getProfile(),
    con object no longer exists.
    Should i use threads or should i just send the main frame as the parameter to create the Connect dialog. If i use threads, how should i code it, and if i use main frame as the parent frame for connect dialog, how do i get the info to main frame. Please help. Here's the code for ConnectDialog. Also, please advice if ConnectDialog code can be improved since i am new to swing. Thanks for helping a needy student.
    public class ConnectDialog extends JDialog{
    private MainFrame parent;
    private String defaultDownloadPath;
    private static Profile currProfile;
    private JList profileList;
    private JPanel listPanel;
    private JPanel infoPanel;
    private JPanel labelPanel;
    private JPanel buttonPanel;
    private JPanel arrangedComponents;
    private Vector data;
    private JLabel ProfileName;
    private JLabel HostAddress;
    private JLabel Account;
    private JLabel PortNo;
    private JLabel login;
    private JLabel password;
    private JLabel DownLoadPath;
    private JButton addButton;
    private JButton cancelButton;
    private JButton connectButton;
    private JButton browseButton;
    private JButton clearButton;
    private JLabel Anonymous;
    private JCheckBox anonymous;
    private JTextField profileName;
    private JTextField hostAddress;
    private JTextField account;
    private JTextField portNo;
    private JTextField loginName;
    private JTextField passwd;
    private JTextField downloadPath;
    private final int textSize = 20;
    private final int fontSize = 12;
    private Container cp;
    public ConnectDialog(MainFrame main) {
    super(main, true);
    parent = main;
    data = new Vector();
    currProfile = new Profile();
    profileList = new JList(data);
    listPanel = new JPanel();
    labelPanel = new JPanel();
    infoPanel = new JPanel();
    buttonPanel = new JPanel();
    arrangedComponents = new JPanel();
    ProfileName = new JLabel("Profile Name:");
    ProfileName.setForeground(Color.black);
    HostAddress = new JLabel("Host Address:");
    HostAddress.setForeground(Color.black);
    Account = new JLabel("Account:");
    Account.setForeground(Color.black);
    PortNo = new JLabel("Port:");
    PortNo.setForeground(Color.black);
    login = new JLabel("Login:");
    login.setForeground(Color.black);
    password = new JLabel("Password:");
    password.setForeground(Color.black);
    DownLoadPath = new JLabel("Download Path:");
    DownLoadPath.setForeground(Color.black);
    addButton = new JButton("Add");
    addButton.setMnemonic('A');
    addButton.setForeground(Color.black);
    cancelButton = new JButton("Cancel");
    cancelButton.setForeground(Color.black);
    clearButton = new JButton("Clear");
    clearButton.setForeground(Color.black);
    connectButton = new JButton("Connect");
    connectButton.setForeground(Color.black);
    connectButton.setMnemonic('C');
    browseButton = new JButton("Browse");
    browseButton.setForeground(Color.black);
    browseButton.setMnemonic('B');
    Anonymous = new JLabel("Anonymous: ");
    Anonymous.setForeground(Color.black);
    anonymous = new JCheckBox();
    profileName = new JTextField(textSize);
    profileName.setText("");
    profileName.setBorder(BorderFactory.createLoweredBevelBorder());
    profileName.setBorder(BorderFactory.createLineBorder(Color.black));
    profileName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    hostAddress = new JTextField(textSize);
    hostAddress.setText("");
    hostAddress.setBorder(BorderFactory.createEtchedBorder());
    hostAddress.setBorder(BorderFactory.createLineBorder(Color.black));
    hostAddress.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    account = new JTextField(textSize);
    account.setText("");
    account.setBorder(BorderFactory.createLoweredBevelBorder());
    account.setBorder(BorderFactory.createLineBorder(Color.black));
    account.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    portNo = new JTextField(5);
    portNo.setText("");
    portNo.setText("21");
    portNo.setBorder(BorderFactory.createEtchedBorder());
    portNo.setBorder(BorderFactory.createLineBorder(Color.black));
    portNo.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    loginName = new JTextField(textSize);
    loginName.setText("");
    loginName.setBorder(BorderFactory.createEtchedBorder());
    loginName.setBorder(BorderFactory.createLineBorder(Color.black));
    loginName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    passwd = new JTextField(textSize);
    passwd.setText("");
    passwd.setBorder(BorderFactory.createEtchedBorder());
    passwd.setBorder(BorderFactory.createLineBorder(Color.black));
    passwd.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    downloadPath = new JTextField(textSize);
    downloadPath.setText("");
    downloadPath.setBorder(BorderFactory.createEtchedBorder());
    downloadPath.setBorder(BorderFactory.createLineBorder(Color.black));
    downloadPath.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    cp = this.getContentPane();
    this.setBounds(200,200,600,300);
    this.setResizable(false);
    cp.setLayout(new BorderLayout());
    setListPanel();
    setLabelPanel();
    setButtonPanel();
    setActionListeners();
    this.setBackground(Color.lightGray);
    this.setVisible(true);
    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    public String getDefaultDownloadPath() {
    return defaultDownloadPath;
    // public Profile getProfile() {
    // try {
    // this.wait();
    // } catch (Exception e) {}
    // return currProfile;
    public void setListPanel() {
    profileList.setFont(new Font("Dialog", Font.PLAIN, 12));
    profileList.setBackground(Color.white);
    profileList.setForeground(Color.black);
    profileList.setPrototypeCellValue("MMMMMMMMM");
    listPanel.setPreferredSize(profileList.getPreferredScrollableViewportSize());
    listPanel.setBorder(BorderFactory.createEtchedBorder());
    listPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    listPanel.setBackground(Color.white);
    listPanel.add(profileList);
    cp.add(listPanel, "West");
    public void setLabelPanel() {
    arrangedComponents = new JPanel();
    arrangedComponents.setLayout(new BorderLayout());
    labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
    labelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    JPanel row1 = new JPanel();
    row1.add(ProfileName);
    labelPanel.add(row1);
    JPanel row2 = new JPanel();
    row2.add(HostAddress);
    labelPanel.add(row2);
    JPanel row3 = new JPanel();
    row3.add(Account);
    labelPanel.add(row3);
    JPanel row4 = new JPanel();
    row4.add(PortNo);
    labelPanel.add(row4);
    JPanel row5 = new JPanel();
    row5.add(login);
    labelPanel.add(row5);
    JPanel row6 = new JPanel();
    row6.add(password);
    labelPanel.add(row6);
    JPanel row7 = new JPanel();
    row7.add(DownLoadPath);
    labelPanel.add(row7);
    infoPanel.setLayout(new BoxLayout(infoPanel,BoxLayout.Y_AXIS));
    infoPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    row1 = new JPanel();
    row1.add(profileName);
    row1.add(profileName);
    infoPanel.add(row1);
    row2 = new JPanel();
    row2.add(hostAddress);
    row2.add(hostAddress);
    infoPanel.add(row2);
    row3 = new JPanel();
    row3.add(account);
    infoPanel.add(row3);
    row4 = new JPanel();
    row4.setLayout(new FlowLayout());
    row4.add(portNo);
    row4.add(Box.createHorizontalStrut(57));
    row4.add(Anonymous);
    row4.add(anonymous);
    infoPanel.add(row4);
    row5 = new JPanel();
    row5.add(loginName);
    infoPanel.add(row5);
    row6 = new JPanel();
    row6.add(passwd);
    infoPanel.add(row6);
    row7 = new JPanel();
    row7.setLayout(new FlowLayout());
    row7.add(downloadPath);
    row7.add(browseButton);
    infoPanel.add(row7);
    arrangedComponents.add(labelPanel, "West");
    arrangedComponents.add(infoPanel, "Center");
    cp.add(arrangedComponents, "Center");
    public void setButtonPanel() {
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(addButton);
    buttonPanel.add(connectButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(clearButton);
    cp.add(buttonPanel, "South");
    public void setActionListeners() {
    anonymous.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(anonymous.isSelected()) {
         loginName.setText("anonymous");
         passwd.setText("your email here");
         else {
         loginName.setText("");
         passwd.setText("");
    addButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(profileName.getText() != "" && !data.contains(profileName.getText())){
         data.add(profileName.getText());
         profileList.setListData(data);
    connectButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         connectButtonPressed();
    cancelButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JButton b = (JButton) e.getSource();
         ConnectDialog c = (ConnectDialog) b.getTopLevelAncestor();
         c.dispose();
    clearButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         profileName.setText("");
         hostAddress.setText("");
         account.setText("");
         portNo.setText("");
         loginName.setText("");
         passwd.setText("");
         downloadPath.setText("");
    browseButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JFrame browseFrame = new JFrame("browse for folder");
         browseFrame.setBounds(230,230,200,200);
         JDirectoryChooser fileChooser = new JDirectoryChooser();
         fileChooser.setFileSelectionMode(JDirectoryChooser.DIRECTORIES_ONLY);
         int option = fileChooser.showDialog(browseFrame);
         if(option==JFileChooser.APPROVE_OPTION) {
         File f = fileChooser.getSelectedFile();
         defaultDownloadPath = f.getAbsolutePath();
         downloadPath.setText(defaultDownloadPath);
    public void connectButtonPressed() {
    if(!profileName.getText().equals("") && !hostAddress.getText().equals("") &&
    !loginName.getText().equals("") && !passwd.getText().equals("")) {
    currProfile.setProfileName(profileName.getText());
    currProfile.setHostAddress(hostAddress.getText());
    currProfile.setAcct(account.getText());
    currProfile.setUserName(loginName.getText());
    currProfile.setPassword(passwd.getText());
    currProfile.setDownloadPath(downloadPath.getText());
    parent.setProfile(currProfile);
    this.dispose();
    else {
    JFrame f = new JFrame("Error!");
    JOptionPane.showMessageDialog(f, "Some fields empty!", "", JOptionPane.ERROR_MESSAGE);
    }

    If the dialog is modal then you can just call show and wait for it to close by the user, then grab the info:
    ConnectDialog dialog = new ConnectDialog();
    dialog .show();
    Profile profile = con.getProfile();
    makeNewConnection( profile );

  • Is it a bug? setIconImage locks the GC

    When I set the icon on the JFrame ( this.setIconImage(...) ) , everything seems well except when I dispose this JFrame, the garbage collector doesn't free the memory. If I don't set the icon the memory is diposed. I have tested this code with netbeans profiler on Linux and Windows and the behavior is exactly the same.
    Any idea?

    When I set the icon on the JFrame (
    this.setIconImage(...) ) , everything seems well
    except when I dispose this JFrame, the garbage
    collector doesn't free the memory. If I don't set the
    icon the memory is diposed. I have tested this code
    with netbeans profiler on Linux and Windows and the
    behavior is exactly the same.
    Any idea?http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6354655
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4649647

  • Command issue

    What command do I use in a JFrame to make the program stop?

    That should work too. I suggested System.exit(), because, the OP did not mention when the app is to be stopped (is it when the JFrame is closed or when some event inside JFrame occurs).
    If it is in an event, invoking dispose() on JFrame object will work but it does not guarantee termination of application if there is any other non-daemon thread is running.
    Another advantage of using System.exit() is it allows us to specify the exit code for the program.

  • Rwrun60 command issue

    Hi,
    I am using rwrun60 command to invoke report builder through a shell script. the report builder and the shell script exists on a differenr machines.
    What is the syntax and commaand/paramaters to be used?
    the current piece of code i am using in the shell script is sa below and it is not working
    rwrun60 module=${UNCPATH}/${REPORT_DIR}/purchase.rdf userid=$DBID/$DBPASS@$DB paramform=NO batch=YES destype=File desformat=pdf desname=${SENDFILE}

    That should work too. I suggested System.exit(), because, the OP did not mention when the app is to be stopped (is it when the JFrame is closed or when some event inside JFrame occurs).
    If it is in an event, invoking dispose() on JFrame object will work but it does not guarantee termination of application if there is any other non-daemon thread is running.
    Another advantage of using System.exit() is it allows us to specify the exit code for the program.

  • Pressing enter to add a row?

    I recently upgraded to Numbers 3.5.2.  Prior to the upgrade, if I wanted to add a row to a table, I simply pressed 'Enter' and a row automatically added below whatever cell was currently selected.  It also added the data entered into the new cell to the formula of the cell(s) above it.  Since upgrading, I have to manually add a row and include the data in the formula...  Any ideas if this is simply a setting?  If so, which one?!

    th eeasiest way to do this is to implement an ActionListener 9which then, you must implement the actionPerformed(ActionEvent e) method
    example:
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    class Demo extends JFrame implements ActionListener{
        private JButton btnExit = null;
        private JButton btnBrowse = null;
        public Demo(){
            btnExit = new JButton("Exit");
             // tell what action listener to use, which is this class (since we implements
            //  the ActionListener
            btnExit(AddActionListener(this);               
            getContentPane().add(btnExit, "South");
            btnBrowse = new JButton("Browse");
            btnBrowse.addActionListener(this);
       // This method is the implementation of the ActionListener interface
        public void actionPerformed(ActionEvent e){
            Object o = event.getSource();  // return the object that trigger the action event
            if (o == btnExit){  // the object triggered is the exit button
                this.dispose();  // dispose the JFrame
                System.exit(0); // wuit the application
            else if (o == btnBrowse){
                JFileChooser fc = new JFileChooser();
                // etc...
    }

  • Email client help needed

    Hello all!!
    I have changed from windows based laptop to a mac laptop, I thought it would be better, but so far, it has been a tough problem, my problem is too many programs are just windows based, but that has been solved with parallels..
    now the main problem lies with my email workflow, as I have been using outlook for a lot of years, I am really used to it and its functionality, but now... I am getting head on with this issue, I cant sync the contacts in my outlook program with my contacts in the iphone (if this was a small problem I would do it manually but I have over 3,000 contacts in my outlook program that I cant dispose of) and I need them to be readily available within my iphone and viceversa.
    I think I have to give up trying to sync outlook and mac contacts as I believe there is no option to do that (baffles me..)
    please do recommend an email client for mac, that I can:
    -sync all my previous emails from the past years (this means almost 10gb of pst files from outlook)
    -be able to sync contacts and calendar in the laptop and the iphone and obviously ipad.
    -be able to filter and search for anything within the email client
    -be able to work as seamless as possible or similar to outlook..  (i never liked mail from mac)
    any ideas? any help will be very much appreciated!!!!
    thanks!!!!!

    KiltedTim
    1, I will try and change that to oulook, but as that is by far not my primary email, there are no issues with that email account, all the email I have is either personal (cancun.com.mx) or work related (all other domains, pani.com.mx, etc)
    I will try and contact this people, but I am afraid this will be a lost battle... they are really backwards...
    now, this gives me an idea, do you think that godaddy can do this contact syncing via the server??
    I may try and change the service, as I am not ok with my current provider, but godaddy is way expensive and I am not sure it would good economic idea..
    and third.. do you recommend anyone? I now that as this is not a country specific issue, I can change to any provider I want, the only issue would be the support if I am in problems, the phone call would be international long distance and not cheap...
    mmmmmm got to think about this..

  • How do i find the visible area...

    Hi everyone.
    I'm trying to get the size of the visible area of a JFrame, but it keeps returning 0. I use this.contantpane().getsize() . Its because I need a drawing area which occupies a certain area of the contentpane. How can I find the visible area without the toolbar and border around the frame?
    Here is my code:
    public class CgraphForm extends JFrame implements Runnable {
        private int h = 600; // Height of JFrame
        private int w = 800; // Width of JFrame
        private double pad; // Padding edges size [%]
        private JButton btClose = new JButton();
        private CGUI gui;
        private boolean running = true;
        public CgraphForm(CGUI _gui) {
            // Name of frame send to parent (super) which is the JFrame
            super("Temperature");
            gui = _gui; // Used to enable the applet again
            pad = 0.05 * h;
            System.out.println("GraphForm thread started");
           try {
               jbInit();
           } catch (Exception ex) {
               ex.printStackTrace();
        public void run() {
            // Interrupt makes the thread terminate proberly by ending its run method
            while (running) {
                try {
                    Thread.currentThread().sleep(100);
                } catch (InterruptedException ex) {
                    running = false;
        private void jbInit() throws Exception {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE); // Disposes the JFrame when its closed
            this.setSize(w,h);
            this.setLocationRelativeTo(null); // Location af JFrame on screen
            this.addWindowListener(new CgraphForm_this_windowAdapter(this));
            Container contentPane = this.getContentPane();
            Dimension size = contentPane.getSize();
            System.out.println(size);
            contentPane.setLayout(new XYLayout());
            // PENDING graphSize mangler et offset paa bredden, sandsynligvis kanten af framen
            Dimension graphSize = new Dimension( (int) (w - 2 * pad),
                                                 (int) (h - 0.45 * h));
            JPanel panel = new JPanel;
            contentPane.add(panel, new XYConstraints((int)pad,(int)pad,(int)graphSize.getWidth(),(int)graphSize.getHeight()));
            this.setVisible(true);
            btClose.setText("Close window");
            btClose.addActionListener(new CgraphForm_btClose_actionAdapter(this));
            contentPane.add(btClose, new XYConstraints((int)pad, 500, -1, -1));
    }/lars

    I need the size to draw my panel.
    You shouldn't do. Your panel should be able to draw itself without knowing its size. Assuming your panel is just a plain space which you draw on, that means one of two things: either you make its rendering logic sensitive to its own size (which you can detect in the paint() method) or you can assign it a preferred size and then place it in a JScrollPane to ensure that it can always be viewed. Both of these are fairly straightforward solutions.

  • Multiple Menu Program

    Hi,
    I want to create a program in Java, and I am using JFrames for my GUI. What the program does is that it has some buttons on a JFrame and each button does an event. One of this buttons has to lead in a new menu.
    I have decided that the best way to do this is to create two JFrames, set the one to visible (i.e. setVisible(true)) and the other one invisible (i.e setVisible(false))
    When I press on the button I want the first frame to become invisible and the second one visible so I will be able to view the new menu.
    Is there any way to do this? If you want my code so far I can post it here, just let me know guys.
    Thanks

    pisaia wrote:
    Card layout does not seem to be the correct!!
    What I want is like a JFrame with a menu (buttons menu), and when you press a button you are transferred to a new JFrame with other buttons. Once you are transferred to the new JFrame the old JFrame has to disappear.I see what you mean, my previous group project created similar functionality where our main GUI displayed four large buttons with an icon on each, where each button opened a new JFrame to a specific area in our application and closed the existing frame.
    Inside your main JFrame create a method for example:
    private void openJFrameX() {
      //create show new JFrame
      new JFrameX();
      //dispose current JFrame
      this.dispose();
    }Then call the method when the corresponding button is pressed.
    On a side note, the reason we took the above approach was due to each of the four JFrame's being independent elements. In regards to a menu, you may want to rethink this design as advised already.
    Mel

Maybe you are looking for