cardlayout

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

青春壹個敷衍的年華 提交于 2019-11-27 08:48:12
问题 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

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

被刻印的时光 ゝ 提交于 2019-11-27 08:28:06
问题 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

Java CardLayout JPanel moves up, when second JPanel added

泄露秘密 提交于 2019-11-27 08:12:34
问题 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

How to wait for a JFrame to close before continuing?

亡梦爱人 提交于 2019-11-27 07:54:09
问题 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

How to change card layout panels from another panel?

試著忘記壹切 提交于 2019-11-27 05:34:30
问题 I Googled for a lot, and no solutions found. I think there shall be java masters to help me out ... This is my initialize method: private void initialize() { this.setSize(750, 480); this.setContentPane(getJContentPane()); this.setTitle("Registration"); JPanel topPane = new TopPane(); this.getContentPane().add(topPane,BorderLayout.PAGE_START); cards=new JPanel(new CardLayout()); cards.add(step0(),"step0"); cards.add(step1(),"step1"); cards.add(step2(),"step2"); this.getContentPane().add(cards

Clear components of JFrame and add new components

半世苍凉 提交于 2019-11-27 05:22:48
I have a JFrame , which have some options. When OK button is pressed i want the same JFrame to clear the contents and add new contents. I have tried it but the problem is new JFrame is popped out. What am I doing wrong? import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; public class GuiFrame extends JFrame { final JFrame f = new JFrame("Test"); public void Starter(){

How to show different cards in a CardLayout?

早过忘川 提交于 2019-11-27 03:36:27
问题 I looked at a code example that used this code: cl.show(cardPanel, "" + (currentCard)); But when I use show I get a message in Eclipse that it's deprecated and I wonder if there is another way to show the different cards in the CardLayout when I click on the buttons? Below is the code for my CardLayout class. Suggestions are also welcome if some part of the code are bad practise. Thanks! import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax

How to get the top card in Java's CardLayout

偶尔善良 提交于 2019-11-27 03:18:44
问题 Is it possible to get the top card in Java's CardLayout? I've tried looping through each component to check for visibility with isVisible() but it seems that they're all "visible". Edit: By "top card" I mean the one that's currently at the "top", being displayed, not the first or last cards. Also, I don't know if it helps but I'm looking for a JPanel (or a subclass thereof) Edit: Code snippet for (Component component : getComponents()) { if (component instanceof JPanel && component.isVisible(

What's so special about CardLayout vs manual adding/removal of JPanels?

空扰寡人 提交于 2019-11-27 02:13:00
问题 There have been many times on StackOverflow where a user asks a question like this... I have a main JPanel that contains a child JPanel . When the user clicks a button, the child JPanel should change to a different JPanel . How can I achieve this. More often than not, the user has actually tried to implement this problem, but can't get it working. Whenever I answer this question, I tell them to do something like this (put simply)... JPanel myFrame = new JPanel(); myFrame.remove(oldPanel);

Make an added JPanel visible inside a parent JPanel

梦想与她 提交于 2019-11-26 23:31:30
问题 How to make an added JPanel visible inside a parent JPanel ? I am using Netbeans for designing my UI. I have a MainFrame.java , which contains two panels; namely headerPanel and bodyPanel . In headerPanel I have put three buttons,let it be button1 , button2 and button3 . Also I have created three separate files extending JPanel , name it panel1 , panel2 and panel3 . Then I added all my three panels inside bodypanel in MainFrame.java in constructor. bodyPanel.add(panel1); bodyPanel.add(panel2)