How to show and hide an existing JFrame












0















I am doing some basic tests to understand how Java Swing works.



I have a test application which consist of three fully independent windows (JFrames):




  1. Main Menu

  2. Asset Window 1

  3. Asset Window 2


The Main Menu has a JButton which will show/hide Asset Window 1 (a1).



This is the main class to launch all windows:



package test1;

import test1.AssetList.AssetList;
import test1.MainMenu.MainMenu;
import javax.swing.*;

public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainMenu m = new MainMenu();
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
}
});
}
}


This is the class with the Asset Window JFrame:



package test1.AssetList;

import javax.swing.*;

public class AssetList extends JFrame {

public AssetList() {

JLabel label = new JLabel("Asset list");
this.getContentPane().add(label);

this.pack();
this.setVisible(false);

}

}


This is the class for the MainMenu JFrame:



package test1.MainMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;

public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener());

this.pack();
this.setVisible(true);

}

}


This is the class for the Asset Window Button JButton listener:



package test1.MainMenu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonAssetListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent evt) {

System.out.println("CLICK!");
/* PSEUDOCODE
if(a1 from Test1.isVisible()==true) {
a1 from Test1.setVisible(false);
} else {
a1 from Test1.setVisible(true);
}
*/
}

}


How can I retrieve the a1 instance from ButtonAssetListener in order to toggle its visibility?
Is there a better alternative to structure this kind of multiple windows application in Java Swing?










share|improve this question

























  • You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

    – camickr
    Nov 14 '18 at 20:00











  • See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 14 '18 at 21:47











  • @AndrewThompson thanks for your comments. I will read the post throughly

    – M.E.
    Nov 14 '18 at 21:55











  • Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

    – M.E.
    Nov 14 '18 at 22:17











  • @AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

    – M.E.
    Nov 14 '18 at 23:11
















0















I am doing some basic tests to understand how Java Swing works.



I have a test application which consist of three fully independent windows (JFrames):




  1. Main Menu

  2. Asset Window 1

  3. Asset Window 2


The Main Menu has a JButton which will show/hide Asset Window 1 (a1).



This is the main class to launch all windows:



package test1;

import test1.AssetList.AssetList;
import test1.MainMenu.MainMenu;
import javax.swing.*;

public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainMenu m = new MainMenu();
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
}
});
}
}


This is the class with the Asset Window JFrame:



package test1.AssetList;

import javax.swing.*;

public class AssetList extends JFrame {

public AssetList() {

JLabel label = new JLabel("Asset list");
this.getContentPane().add(label);

this.pack();
this.setVisible(false);

}

}


This is the class for the MainMenu JFrame:



package test1.MainMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;

public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener());

this.pack();
this.setVisible(true);

}

}


This is the class for the Asset Window Button JButton listener:



package test1.MainMenu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonAssetListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent evt) {

System.out.println("CLICK!");
/* PSEUDOCODE
if(a1 from Test1.isVisible()==true) {
a1 from Test1.setVisible(false);
} else {
a1 from Test1.setVisible(true);
}
*/
}

}


How can I retrieve the a1 instance from ButtonAssetListener in order to toggle its visibility?
Is there a better alternative to structure this kind of multiple windows application in Java Swing?










share|improve this question

























  • You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

    – camickr
    Nov 14 '18 at 20:00











  • See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 14 '18 at 21:47











  • @AndrewThompson thanks for your comments. I will read the post throughly

    – M.E.
    Nov 14 '18 at 21:55











  • Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

    – M.E.
    Nov 14 '18 at 22:17











  • @AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

    – M.E.
    Nov 14 '18 at 23:11














0












0








0








I am doing some basic tests to understand how Java Swing works.



I have a test application which consist of three fully independent windows (JFrames):




  1. Main Menu

  2. Asset Window 1

  3. Asset Window 2


The Main Menu has a JButton which will show/hide Asset Window 1 (a1).



This is the main class to launch all windows:



package test1;

import test1.AssetList.AssetList;
import test1.MainMenu.MainMenu;
import javax.swing.*;

public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainMenu m = new MainMenu();
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
}
});
}
}


This is the class with the Asset Window JFrame:



package test1.AssetList;

import javax.swing.*;

public class AssetList extends JFrame {

public AssetList() {

JLabel label = new JLabel("Asset list");
this.getContentPane().add(label);

this.pack();
this.setVisible(false);

}

}


This is the class for the MainMenu JFrame:



package test1.MainMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;

public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener());

this.pack();
this.setVisible(true);

}

}


This is the class for the Asset Window Button JButton listener:



package test1.MainMenu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonAssetListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent evt) {

System.out.println("CLICK!");
/* PSEUDOCODE
if(a1 from Test1.isVisible()==true) {
a1 from Test1.setVisible(false);
} else {
a1 from Test1.setVisible(true);
}
*/
}

}


How can I retrieve the a1 instance from ButtonAssetListener in order to toggle its visibility?
Is there a better alternative to structure this kind of multiple windows application in Java Swing?










share|improve this question
















I am doing some basic tests to understand how Java Swing works.



I have a test application which consist of three fully independent windows (JFrames):




  1. Main Menu

  2. Asset Window 1

  3. Asset Window 2


The Main Menu has a JButton which will show/hide Asset Window 1 (a1).



This is the main class to launch all windows:



package test1;

import test1.AssetList.AssetList;
import test1.MainMenu.MainMenu;
import javax.swing.*;

public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainMenu m = new MainMenu();
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
}
});
}
}


This is the class with the Asset Window JFrame:



package test1.AssetList;

import javax.swing.*;

public class AssetList extends JFrame {

public AssetList() {

JLabel label = new JLabel("Asset list");
this.getContentPane().add(label);

this.pack();
this.setVisible(false);

}

}


This is the class for the MainMenu JFrame:



package test1.MainMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;

public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener());

this.pack();
this.setVisible(true);

}

}


This is the class for the Asset Window Button JButton listener:



package test1.MainMenu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonAssetListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent evt) {

System.out.println("CLICK!");
/* PSEUDOCODE
if(a1 from Test1.isVisible()==true) {
a1 from Test1.setVisible(false);
} else {
a1 from Test1.setVisible(true);
}
*/
}

}


How can I retrieve the a1 instance from ButtonAssetListener in order to toggle its visibility?
Is there a better alternative to structure this kind of multiple windows application in Java Swing?







java swing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:39









Mark Rotteveel

60.6k1478121




60.6k1478121










asked Nov 14 '18 at 18:25









M.E.M.E.

1,106729




1,106729













  • You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

    – camickr
    Nov 14 '18 at 20:00











  • See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 14 '18 at 21:47











  • @AndrewThompson thanks for your comments. I will read the post throughly

    – M.E.
    Nov 14 '18 at 21:55











  • Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

    – M.E.
    Nov 14 '18 at 22:17











  • @AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

    – M.E.
    Nov 14 '18 at 23:11



















  • You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

    – camickr
    Nov 14 '18 at 20:00











  • See The Use of Multiple JFrames, Good/Bad Practice?

    – Andrew Thompson
    Nov 14 '18 at 21:47











  • @AndrewThompson thanks for your comments. I will read the post throughly

    – M.E.
    Nov 14 '18 at 21:55











  • Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

    – M.E.
    Nov 14 '18 at 22:17











  • @AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

    – M.E.
    Nov 14 '18 at 23:11

















You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

– camickr
Nov 14 '18 at 20:00





You should not be using multiple frames. If you want multiple windows then use a JDialog for the child window to the main parent frame.

– camickr
Nov 14 '18 at 20:00













See The Use of Multiple JFrames, Good/Bad Practice?

– Andrew Thompson
Nov 14 '18 at 21:47





See The Use of Multiple JFrames, Good/Bad Practice?

– Andrew Thompson
Nov 14 '18 at 21:47













@AndrewThompson thanks for your comments. I will read the post throughly

– M.E.
Nov 14 '18 at 21:55





@AndrewThompson thanks for your comments. I will read the post throughly

– M.E.
Nov 14 '18 at 21:55













Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

– M.E.
Nov 14 '18 at 22:17





Even when using multiple JDialogs as child windows among a main parent frame, the question of accessing other windows would be still there.

– M.E.
Nov 14 '18 at 22:17













@AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

– M.E.
Nov 14 '18 at 23:11





@AndrewThompson after reading the post I am not 100% clear if I shall go for multiple JFrames or not. My app will be multi monitor and fully customizable layout must be allowed. Each window will be autonomous and loosely related to other windows. I will probably do a test with both solutions.

– M.E.
Nov 14 '18 at 23:11












1 Answer
1






active

oldest

votes


















1














You can just pass the instance you want to hide to the button listener.



public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
MainMenu m = new MainMenu(a1);
}
});
}
}


Make your main menu take in a component which it will show and hide.



public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu(JComponent assetList) {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener(assetList));

this.pack();
this.setVisible(true);

}

}


Then modify your your button asset listener to take in a component which it will then show or hide.



public class ButtonAssetListener implements ActionListener{

private JComponent component;

public ButtonAssetListener(JComponent component) {
this.component = component;
}

@Override
public void actionPerformed(ActionEvent evt) {
if(component.isVisible()) {
component.setVisible(false);
} else {
component.setVisible(true);
}
}
}





share|improve this answer
























  • I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

    – M.E.
    Nov 14 '18 at 22:18













  • @M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

    – ug_
    Nov 15 '18 at 0:12











  • Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

    – M.E.
    Nov 15 '18 at 0:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306585%2fhow-to-show-and-hide-an-existing-jframe%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can just pass the instance you want to hide to the button listener.



public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
MainMenu m = new MainMenu(a1);
}
});
}
}


Make your main menu take in a component which it will show and hide.



public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu(JComponent assetList) {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener(assetList));

this.pack();
this.setVisible(true);

}

}


Then modify your your button asset listener to take in a component which it will then show or hide.



public class ButtonAssetListener implements ActionListener{

private JComponent component;

public ButtonAssetListener(JComponent component) {
this.component = component;
}

@Override
public void actionPerformed(ActionEvent evt) {
if(component.isVisible()) {
component.setVisible(false);
} else {
component.setVisible(true);
}
}
}





share|improve this answer
























  • I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

    – M.E.
    Nov 14 '18 at 22:18













  • @M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

    – ug_
    Nov 15 '18 at 0:12











  • Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

    – M.E.
    Nov 15 '18 at 0:19
















1














You can just pass the instance you want to hide to the button listener.



public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
MainMenu m = new MainMenu(a1);
}
});
}
}


Make your main menu take in a component which it will show and hide.



public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu(JComponent assetList) {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener(assetList));

this.pack();
this.setVisible(true);

}

}


Then modify your your button asset listener to take in a component which it will then show or hide.



public class ButtonAssetListener implements ActionListener{

private JComponent component;

public ButtonAssetListener(JComponent component) {
this.component = component;
}

@Override
public void actionPerformed(ActionEvent evt) {
if(component.isVisible()) {
component.setVisible(false);
} else {
component.setVisible(true);
}
}
}





share|improve this answer
























  • I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

    – M.E.
    Nov 14 '18 at 22:18













  • @M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

    – ug_
    Nov 15 '18 at 0:12











  • Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

    – M.E.
    Nov 15 '18 at 0:19














1












1








1







You can just pass the instance you want to hide to the button listener.



public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
MainMenu m = new MainMenu(a1);
}
});
}
}


Make your main menu take in a component which it will show and hide.



public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu(JComponent assetList) {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener(assetList));

this.pack();
this.setVisible(true);

}

}


Then modify your your button asset listener to take in a component which it will then show or hide.



public class ButtonAssetListener implements ActionListener{

private JComponent component;

public ButtonAssetListener(JComponent component) {
this.component = component;
}

@Override
public void actionPerformed(ActionEvent evt) {
if(component.isVisible()) {
component.setVisible(false);
} else {
component.setVisible(true);
}
}
}





share|improve this answer













You can just pass the instance you want to hide to the button listener.



public class Test1 {

public static void main(String args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
AssetList a1 = new AssetList();
AssetList a2 = new AssetList();
MainMenu m = new MainMenu(a1);
}
});
}
}


Make your main menu take in a component which it will show and hide.



public class MainMenu extends JFrame {

JLabel label = new JLabel("Main Menu");
JButton button = new JButton("Asset");

public MainMenu(JComponent assetList) {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(label);
this.getContentPane().add(button);

button.addActionListener(new ButtonAssetListener(assetList));

this.pack();
this.setVisible(true);

}

}


Then modify your your button asset listener to take in a component which it will then show or hide.



public class ButtonAssetListener implements ActionListener{

private JComponent component;

public ButtonAssetListener(JComponent component) {
this.component = component;
}

@Override
public void actionPerformed(ActionEvent evt) {
if(component.isVisible()) {
component.setVisible(false);
} else {
component.setVisible(true);
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 18:53









ug_ug_

8,88722444




8,88722444













  • I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

    – M.E.
    Nov 14 '18 at 22:18













  • @M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

    – ug_
    Nov 15 '18 at 0:12











  • Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

    – M.E.
    Nov 15 '18 at 0:19



















  • I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

    – M.E.
    Nov 14 '18 at 22:18













  • @M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

    – ug_
    Nov 15 '18 at 0:12











  • Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

    – M.E.
    Nov 15 '18 at 0:19

















I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

– M.E.
Nov 14 '18 at 22:18







I was recommended (outside stack overflow) to use a class with JFrames as static resources. Class can be instantiated across different entities and JFrames can be accessed. I was adviced to use this solution in a single-user application. Moving arguments across different classes can be cumbersome when dealing with a large number of windows.

– M.E.
Nov 14 '18 at 22:18















@M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

– ug_
Nov 15 '18 at 0:12





@M.E. I would agree with that in general. However in your case you have 1 or more "AssetList" frames where in many applications you have 1 WinMain type class. This solution is just one way of doing it, maybe instead you want to do something with a registry of sorts where windows are registered then your MainMenu can look at that registry and see whats there. Might be a better way for your use case.

– ug_
Nov 15 '18 at 0:12













Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

– M.E.
Nov 15 '18 at 0:19





Thanks for further commenting on your answer. As part of the recommendation the registry method you are mentioning was raised. As of now I am doing just very basic steps as I need to learn Swing (I have used other widget frameworks in other languages in the past, but not Swing), but I will move into sort kind of registry if that makes sense (which is probably the case as the number of windows will be variable). I will incorporate all that gradually.

– M.E.
Nov 15 '18 at 0:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306585%2fhow-to-show-and-hide-an-existing-jframe%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine