cardlayout

CardLayout get the selected card's name

我只是一个虾纸丫 提交于 2019-12-01 01:09:31
问题 How can I get the string identifier of the selected panel in card layout. 回答1: The CardLayout does not know what the currently selected panel is. You should keep this in memory yourself, when calling the show() method. 回答2: The CardLayout does not allow you to do this. However, you should be able to access the top panel of the CardLayout. So a little work around is to give each added panel a name, equal to the string identifier. That way you can get the top card, and get it's name. This is

Adding ChartPanel to CardLayout

爷,独闯天下 提交于 2019-11-29 17:02:49
I have a pretty basic GUI organized with a GridBagLayout . The most complex portion is the bottom where West is populated with ScrollPane and the right is a panel with a CardLayout that has multiple ChartPanels so I can switch between a few graphs. My issue comes when I start the program. The resizing issue goes away after I resize the frame in any direction. I have confirmed the chartpanel is the issue because not adding this to the CardLayout panel fixes it. I create a blank ChartPanel and populate it later after some action is taken but this is what I've done: public class Tester { public

CardLayout in Java change by action in one of the 'cards'

不想你离开。 提交于 2019-11-29 15:12:50
I am making a simple game using a JFrame . I have made a simple "Start" screen which basically consists of a String and a JButton . I am picking up the button click with the actionPerformed(ActionEvent e) method. I don't know how to change the cards using a button click. This may seem like a simple problem to solve, but the twist comes with this: My main JFrame, my StartScreen and my JPanel where the game takes place are all in separate files. My main file, Virus.java, is where I create the JFrame . My file VirusGamePanel.java is where the game takes place. My file StartScreen.java is the

A individual class for each Card in java swing CardLayout

放肆的年华 提交于 2019-11-29 12:09:59
For architecture and design purposes I would like to design my GUI with a class for each card in a Java Swing CardLayout. and then have a mainapp that builds the GUI. I am having trouble doing this right now. I would like to example have a class for the main menu with all the button locations etc. and then just instantiate that card and add it to the layout in another class. Does anyone know how to achieve this? Perhaps you want to give your class that uses the CardLayout a public loadCard method, something like public void loadCard(JComponent component, String key) { cardHolderPanel.add

How to set a JFrame size to fit the CardLayout displayed JPanel?

时间秒杀一切 提交于 2019-11-29 00:16:27
I have a JFrame containing a set of JPanels in a CardLayout . Each JPanel has a different size and I want the JFrame to adapt to the size of the currently displayed JPanel (not the JPanel to adapt to the size of the JFrame ). How can I achieve this? The general is: if you have a layout problem, always solve it with an appropriate LayoutManager. Never tweak a component's sizing hint to reach your goal. In this case, it's particularly easy to adjust the CardLayout. By default, it calculates its prefSize to the max of prefSizes of all cards. Simply subclass and implement to return the prefSize

Singleton with CardLayout won't show card when another class calls Singleton.instance.show()

天涯浪子 提交于 2019-11-28 14:47:58
public class MainWindow extends JPanel { public static MainWindow instance = new MainWindow(); private CardLayout cards = new CardLayout(); public MainWindow() { setLayout(cards); add(new FirstPage(), Pages.FIRST.toString()); add(new SecondPage(), Pages.SECOND.toString()); add(new ThirdPage(), Pages.THIRD.toString()); } public void showPage(Pages page) { cards.show(this, page.toString()); } } the showPage(page); method works fine if I call it in the constructor of MainWindow . But when I try to call MainWindow.instance.showPage(Pages.SECOND); from an ActionListener in FirstPage nothing happens

How do I use CardLayout for my Java Program for Login and Menu Items

十年热恋 提交于 2019-11-28 14:20:12
I am creating a "Store" program that basically can allow an employee to log in with a username and password I provide. After logging in, the employee can then see a "main menu" with four buttons: Sales Register, PLU Settings, Settings, and Logout. From this screen, the employee can proceed by clicking on any of the buttons to navigate to that screen. I do not want a new window to popup every time a button is clicked, but instead I want there to be some transition (or no transition) to go to the page that is clicked. So to give an example: When the employee starts the program, he/she is greeted

Java CardLayout JPanel moves up, when second JPanel added

半城伤御伤魂 提交于 2019-11-28 14:14:07
I am new to Java and mostly CardLayout. I want to simply switch "windows" represented by JPanels. I read somewhere that job for CardLayout. But my problem is, when add chatPanel to mainPanel (this is the CardLayout one), it shifts the content of connectPanel several pixels to the top, away from its centered position. Is I skip in my code createChatPanel(), its where it should be. I have this code: package App; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*;

How to wait for a JFrame to close before continuing?

佐手、 提交于 2019-11-28 13:42:29
My program consists of 3 main 'sections'. Main function, Login form and App form. The main function should do something like: Open Login form, wait for it to close, then open App form. I can't get the waiting part to work, or rather, I don't know how I would go around doing that. I was told by someone to use a JDialog instead and use setModal(true) , but with that approach the Login form wouldn't appear on the taskbar, which is terrible in my opinion. Another thing I considered was to open the App from inside the Login after it closes, but that feels like bad design since that'd make the Login

Adding ChartPanel to CardLayout

我们两清 提交于 2019-11-28 11:36:41
问题 I have a pretty basic GUI organized with a GridBagLayout . The most complex portion is the bottom where West is populated with ScrollPane and the right is a panel with a CardLayout that has multiple ChartPanels so I can switch between a few graphs. My issue comes when I start the program. The resizing issue goes away after I resize the frame in any direction. I have confirmed the chartpanel is the issue because not adding this to the CardLayout panel fixes it. I create a blank ChartPanel and