CardLayout « Layout « Java Swing Q&A





1. Removing a JComponent from a CardLayout    stackoverflow.com

How do I remove a JPanel (or any other JComponent) from a CardLayout? I do not have direct access to the Component I want to remove, but I have the ...

2. CardsLayout in Java Swing    stackoverflow.com

I have taken a JPanel (say cardsPanel) and have set its layout as CardsLayout. After that I have added 3 cards on it (say card1, card2, and card3) all of JPanel ...

3. CardLayout swapping panels    stackoverflow.com

In my project I've got a JPanel (bottomPanel) in a JFrame that needs to be swapped so I'm using a CardLayout on bottomPanel. In my parent JFrame I've essentially got this code ...

4. Switching Between Cards in a CardLayout using getParent()    stackoverflow.com

I am writing an application where I am using the CardLayout to swap between two panels that are placed right on top of one another. There's a JPanel called Top, and it's ...

5. Refresh Panel on CardLayout Swap    stackoverflow.com

How do you refresh a JPanel on the panel change from container CardLayout?

6. CardLayout - making it take the least amount of space necessary    stackoverflow.com

All, I have a form type view I'm creating in Java. Based on the contents of a combobox, I need to switch some aspects of the form. I am using ...

7. Showing the previous tab of CardLayout    stackoverflow.com

I'm having trouble figuring this one out. The situation is no difficult to imagine so I hope I could post this without a sample code. I have JPanel with CardLayout. The panel contains ...

8. How to get the top card in Java's CardLayout    stackoverflow.com

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 ...

9. Strange problem with java CardLayout in JFrame    stackoverflow.com

hello i have a Jframe with a CardLayout and 3 cards. I have an ActionListener on a button on the first card. This code is working well:

JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
 ...





10. Java Swing - CardLayout, how to 'update' cards while running?    stackoverflow.com

I am pretty new at . Java Swing, and am using the CardLayout for my application. In this app a user can create activities and, in an other JPanel, view the ...

11. Change size of JPanel using CardLayout    stackoverflow.com

is it possible to change the size of Jpanels when using Java CardLayout?

12. Java CardLayout JPanel moves up, when second JPanel added    stackoverflow.com

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 ...

13. Updating one card's(JPanel) contents based on input from another card in CardLayout    stackoverflow.com

I have a set of JPanels arranged in CardLayout. The issue is that when I change things in one JPanel, I want the changes to be reflected in another JPanel that ...

14. Check if a card with a name is present in a CardLayout    stackoverflow.com

I have a CardLayout in which I add cards only as needed. So, when the need arises to show a particular card (identifed by its name), I need a way to ...

15. How to change card layout panels from another panel?    stackoverflow.com

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() {
    ...

16. Swing CardLayout and child panel layouts    stackoverflow.com

I have a JXPanel that uses CardLayout. That panel has two cards that work as expected. My problem is when using a child JXPanel to one of the cards ...





17. CardLayout get the selected card's name    stackoverflow.com

How can I get the string identifier of the selected panel in card layout.

18. CardLayout not working properly    stackoverflow.com

I have written this simple Cardlayout example with Splitpane, Combobox and few other panels containing buttons and label.

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import ...

19. CardLayout not completely hiding other cards?    stackoverflow.com

I am building a game, and to switch between the login screen and the game screen, I am using a CardLayout. The code I am using to switch between the screens is

Global.gameScreen ...

20. Java CardLayout Show Problem    stackoverflow.com

Ok me again i need help. For some reason when i click a button the button dissapears but not the panel Here is the code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainMenu extends JPanel ...

21. Cardlayout addLayoutComponent() API    stackoverflow.com

I'm a bit confused by the logic that's been used to arrive at the current API for addLayoutComponent(). There's two methods, one that takes a string and a component, and ...

22. Alternatives to CardLayout that do not hold references to the contained components    stackoverflow.com

I would like to dynamicly replace/change to contents of a panel. I know that the "standard" way of doing this is to use the CardLayout. However, most of the Components are ...

23. JScrollPane added to a CardLayout not displaying in Java 1.6    stackoverflow.com

My application uses Cardlayout with JPanel. On click of a button it should display a JScrollPane. It works fine with Java 1.5, But does not display anything in Java 1.6. Its ...

24. Can't establish absolute dimensions and positioning for JPanel in CardLayout and their associated components in Netbeans 7    stackoverflow.com

I have a few JPanels stacked under a mainPanel via CardLayout under Netbeans 7. Now for some weird reason I can't get any of these JPanels to maintain a setPreferredSize ...

25. How to Use A CardLayout in My Situation    stackoverflow.com

I have not been able to find a way to use a CardLayout that works. I am creating a Pong game. I have a class that extends a JFrame and two classes ...

26. Is there an equivalent to the Swing CardLayout in the Qt Framework?    stackoverflow.com

I am designing an Application using the Qt framework, and I want to avoid using multiple dialogs simply because I think it can get messy with having many dialogs open. I ...

27. How to set a JFrame size to fit the CardLayout displayed JPanel?    stackoverflow.com

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 ...

28. Wrong JPanel displayed in CardLayout. Issues with getGraphics()    stackoverflow.com

I have a top-level GUI class called SpacePotaters (subclass of JFrame) and I add a JPanel called panelViews (which uses the CardLayout layout manager) to its content pane. Among other things, ...

29. CardLayout    coderanch.com

30. Re cardLayout    coderanch.com

Rose, I am not sure exactly what you are trying to do since you didn't post any code, but I've built some test code to try the situation you are describing... try to plug a resonably big image into the test code and it should work... ( replace Washu_BG1.gif with the image of your choice... ) Hopefully, it will illustrate what ...

31. Best approach for CardLayout    coderanch.com

I'm writing an application that uses CardLayout. The first card shows 3 buttons, Edit Add and Finish. The Edit and Add cards have the same layout except for one place. Edit has a drop JComboBox showing current values for the application, Add has a JTextField that allows you to add a new value and submit it. Otherwise, the two cards are ...

32. CardLayout- how to deal with it?    coderanch.com

33. Wizards and CardLayout    coderanch.com

Hi, Im playing about with awt and Swing and Id like to create a wizard like dialog. I figured the easiest way at first glance was to use a cardlayout for the main part of the dialog. The problem Im having is that using the previous() and next() methods of CardLayout, I cant prevent my Next and Previous buttons from looping ...

34. Problem with cardlayout    coderanch.com

Hi Patricia, Quite simply, you are not chaning it! You will need to get a handle on the label that holds the counter: private Label myLabel; Then you will need to assign a label to this: myLabel = new Label( String.valueOf( totalCount ) ); Then you can change it inside your button actionPerformed: totalCount++; myLabel.setText( String.valueOf( totalCount ) ); Regards, Manfred. ...

35. Need Help for CardLayout.    coderanch.com

There is a CardLayout layout manager name clay and has been populated with 5 components whose identifiers are "A", "B", "C", "D", "E". I don't know the order in which the components were added to the container. I know, however, that the component with the identifier "B" is not the first component. In such a case, how could I display the ...

36. How to use CardLayout Manager    coderanch.com

This is what I want: when i click on one of the radio buttons (in the west panel), i want the center panel to display one of 3 cards. problem is, i can't seem to pull it off! here's the code for that particular tab and the action listener method for it: protected Component makeAddPanel() { JPanel addPanel = new JPanel(true); ...

37. Modify card in CardLayout    coderanch.com

Dear All, I need a urgent help from you. I have a class as follow: class Class extends Panel { int cardNo; CardLayout cardLayout; DrawingCardFront cardFront; // DrawingCardFront is a class // extending Canvas Card(int cardNo); super(); this.cardNo = cardNo; setBackground(Color.WHITE); cardLayout = new CardLayout(); cardFront = new DrawingCardFront(cardNo); setLayout(cardLayout); add(new DrawingCardBack(), "Back"); // DrawingCardBack is // another class // extending ...

38. change card (cardlayout) in netbeans    coderanch.com

I have created 2 panels on the left is a menu panel with buttons. i want to use these buttons to change the card shown in cardlayout on the right side panel. The name of the panel on the right is mainPanel and the card name is Student_Home what do i add to the button in order to change card ? ...

39. hopefully simple question on CardLayout    coderanch.com

40. CardLayout and InputVerifier    coderanch.com

In your event code that changes cards check with your verifier(s) that their JComponents are all verified before allowing the cards to change. Here's a demo with code adapted from the InputVerifier api. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class VerifierTest { public static void main(String[] args) { JTextField verified = new JTextField("Type \"pass\" here", 12), plain = new JTextField(12); ...

41. CardLayout    coderanch.com

Hi Matthew, It pretty much depends of other circumstances, but in general the idea of having a class per window or a class per screen is correct. I guess that your screens might have some common characteristics. Then you can derive them from a common base class. Sometimes you might be able to use the same class with different parameters for ...

42. Exception: wrong parent for CardLayout    coderanch.com

Hi everybody, I am creating a GUI for an application. I am setting the frame with CardLayout. But, I am getting runtime exception "java.lang.IllegalArgumentException: wrong parent for CardLayout" while executing the cardLayout.show(Container parent, Object constraints) method. I made sure the parent was the one which has the card layout set to it. Please help. The program is below. public class LoginGUI ...

43. CardLayout problem    coderanch.com

I there, I have the following set-up in my JFrame... public class Main extends JFrame { private static Drawer drawer2=null; private static Drawer drawer3=null; CardLayout cl; public Main() { drawer3=Drawer3.getInstance(102); drawer2=Drawer2.getInstance(102); cl=new CardLayout(); this.getContentPane().setLayout(cl); this.getContentPane().add("blue",drawer3); this.getContentPane().add("red",drawer2); this.setSize(506,550); this.setLocationRelativeTo(null); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } Then to swap the cards I do 'cl.next(getContentPane());' This works, and the new Drawer object is displayed. However, both ...

44. Regarding CardLayout    coderanch.com

Hi, Thanks for your help its working now. But i have one more problem. I want to add a image to a panel which can cover upto 75% of its length. I already have some text fields above. I want to add image on same panel but below the text fields. So please any body can help.

46. Problem with Listeners in CardLayout    coderanch.com

/** * */ package com.sgcib.agora.gui.economic.gpv.view; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ScrollPaneConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import lib.reference.AgrSourceMgr; import lib.reference.BdrFolderMgr; ...

47. CardLayout problems    coderanch.com

48. First land Last card in Cardlayout    coderanch.com

49. special effects for cardlayout of pictures?    coderanch.com

Hi all, I'm new to this forum and Java. Sorry i forgot to say on my first post. But i am also wondering why they use my real name and not login id? Anyhow, I have a cardlayout of pictures in Java and i am wondering if i could code some way for each slide to move in slowly from left ...

50. Cardlayout problem    coderanch.com

wow its a long time since i wrote a message here (or worked on my project at all) but i decided enough was enough i need to set aside some time to work on it. so i have done and i have run into a brick all after about an hour my problem is to do with the show() class in ...

51. CardLayout / JPanel Question    coderanch.com

You don't need to call invokeLater from the EDT itself, except a few cases (like requesting focus). Changing the active panel is not one of them, so from the event handler you can safely change the active panel. From any other thread you'll need invokeLater. Note that in AWT and Swing, nothing should be considered to be thread safe unless explicitly ...

52. Display error in CardLayout    coderanch.com

I having a problem in getting the Card Layout into the display. When I open the applet, I get nothing but a blank area. No errors. I want to click on the Next button, and that should open the card2 layout. Please help me. Here is my code. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class STestFile1 extends JApplet ...

54. Unexpected behavior Thread.sleep() is used within CardLayout    java-forums.org

I am trying to display two panels after each other using CardLayout. Here is a method: public void initComponents() { CardLayout cl = new CardLayout(); setLayout(cl); add(welcomePanel, "Welcome"); cl.show(this, "Welcome"); try { Thread.sleep(3000); } catch (InterruptedException ie) { System.out.println("Caught " + ie.getClass()); } System.exit(0); } From my perspective, the program should show welcomePanel for 3 seconds and then exit. On the ...

55. Refresh CardLayout    java-forums.org

Hi I have several JPanel in a CardLayout. One JPanel is for the login, the second is for the Profil information. When I login, I set the user ID in "static public userID" then I which to the layout "Profil". The problem is that the profil label is set on mainCardLayout.userID and it is showing an empty String. I'm assuming that ...

56. CardLayout Trouble    java-forums.org

I've written this program where you have a CardLayout which switches between two panels based on which of the two buttons are pressed. The problem is that the panels aren't visible. Java Code: import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; 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.JMenu; import javax.swing.JMenuBar; import javax.swing.JPanel; public class Whatever { ...

57. CardLayout and Background image    java-forums.org

Re: CardLayout and Background image Okay, I'll post most of my code here. It has to be a GUI for a project and I'm Dutch so that will explain the button/constructor names. Java Code: public class GUIproj3 extends JFrame implements ActionListener, MouseListener { /*some code*/ private final CardLayout gui = new CardLayout(); private JPanel center = new JPanel(); private Frame frame ...

58. CardLayout with JPanels    java-forums.org

Hi, I'm new with Java... I'm trying to create a simple program with a button which allows to switch between two different background images. I guess I have a problem during the runtime. Here is the error that i obtained: Exception in Thread "main": java.lang.IllegalArgumentException: wrong parent for CardLayout at java.awt.CardLayout.checkLayout(CardLayout.java:38 4) at java.awt.CardLayout.show(CardLayout.java:506) at SetupSfondi.ImpostaSfondi(setupSfondi.java: 41) at SetupSfondi.main(setupSfondi.java:57) Here is ...

59. Regarding CardLayout    java-forums.org

Hi I know that in card layout we can add different cards and switch between them. Now i have add buttons as first, last, next and previous. And i am able to do so by using this buttons.Now what i need is to get a card directly on clicking a button say xyz. Imagine you have 15 cards and you need ...

60. Populating CardLayout JPanels with External classes    java-forums.org

public class Nascar implements ActionListener { JPanel cards; final static String SIGNIN="Sign in"; final static String EXIT="Exit"; final static String FORGOTPASSWORD="Forgot your password?"; Icon logo = new ImageIcon ("logo.//gif"); public void addComponentToPane(Container pane) { JPanel card1 = new JPanel(); JButton signIn = new JButton(SIGNIN, logo); signIn.setActionCommand(EXIT); signIn.addActionListener(this); card1.add(signIn); JButton forgotPassword = new JButton(FORGOTPASSWORD); forgotPassword.setActionCommand(EXIT); forgotPassword.addActionListener(this); card1.add(forgotPassword); LogonScreen card2 = new LogonScreen(); ...

61. JFrame and CardLayout -- Wrong Parent    java-forums.org

So here is my code. It is three parts, 2 are shown, the last is not relevant: Java Code: //First file import javax.swing.*; import java.awt.event.*; import java.lang.String; import java.lang.Object; import java.util.Formatter; import java.awt.*; public class ToDoItBetterAgain extends JFrame { //Attributes private CardLayout myCard; private MainPanel mainPanel; private AddPanel addPanel; public static void main(String[] args) { new ToDoItBetterAgain(); } ToDoItBetterAgain() { this.setSize(600,400); ...

62. Adding JScrollPane to CardLayout    forums.oracle.com