CardLayout Problems

When switching cards using the show() method some of the contents of the card is not shown. On the card that has the problem I have a JSplitPane with two JScrollPane's in the JSplitPane. In the JScrollPane's I use a JPanel with the null layout. The contents of the JScrollPane do not appear. If I start the applet showing the card with the problem everything shows fine. If I start the applet showing another card and then switch to the card in question this is when the problem occurs. Any advice would be greatly appreciated.

Hey thanks for the response, I never thought anyone would touch this >one. :) you rock.np, that's what the forum is here for. And after all I'm just TRYING to help...;)
according to what you said it really seems to be a resizing prob, 'cause
Have you ever tried starting the applet with the
prob-card on top, switching to another one and then
switching back? what happens, the card is still ok?Yes, and everything is fine. this speaks quite in it's favor....
If the applet does not change size however, no matter what card you start it with, this (could) mean two things (assuming that it is, in fact, a resizing problem):
first possibiliy: other components within the card are resized to their downside when sarting with the prob-causing card so that it has enough space, when starting with the 'standard'-one they are not scaled down not leaving place for the rpob-causing card.
second: it has to do with the embedding in the html environment, I mean, the size of the area grantet to the applet is absolutely constant, and when starting with the prob-causer a bit of the applets'border is cut off, just like putting a picture frame over a too big photograph...
As for the second (possible) case: try to alter the embedding settings, in order to leave enough space to the applet or someting...
And for the first:...well, I know it's a vague advice but...try to remove ANY other items from the applet leaving just the cards, and play around with it....
I'll post as soon as something more productive crosses my mind..(but that will be after the xmas vacation, I guess ;D
btw.: ever tried to run the same applet in a tabbed pane instead of the card layout and see what happens?
p.s:merry xmas, so long...

Similar Messages

  • CardLayout problem, urgent

    Hi friends,
    I am building a Swing GUI, i have a cardlayout managment, my GUI is dynamic that is every certain period of time new data are coming and new figures are being drawn in my GUI. The GUI containes menus, when you press on any menu list of items are listed for you, when you press on an item a page opens, when you press on another item, a new page opens, those pages are layouted in a cardlayout managment, each page is in top of another. I am getting a problem, when i am opening page 2 for example, and a new set of data comes in and the figure in page 1 is updated, i am automatically moved from page 1 to page 2 where the update happened, although i didn't press the item in the menu to go to that page where the update happened, please would anyone suggest me something, it is very urgent, and if someone wants the code i can supply it for sure, thanks for the help.

    Maybe an itemStateChanged -Event is invoked when the page is updated.

  • CardLayout problem. This is totally weird....

    Hi...
    I have some code which uses a CardLayout to show two different panels. Card A is a "loading" type panel telling the user to wait as background stuff is being done. Card B displays data from the database.
    showCardA()
    do some stuff.... (get data from database which takes around 5 seconds)
    showCardB()
    For some strange reason, card A is never shown. If I comment out showCardB(), card A is displayed correctly. The database call is about 5 seconds so it's not flipping through too quickly.
    I am using CardLayout correctly, but I am thinking that the problem has something to do with threading issues?????
    This bug is totally totally baffling me.

    You're blocking the event dispatch thread with your database stuff.
    See http://spin.sourceforge.net for an explanation and a possible solution.
    Sven

  • CardLayout : problem on previous card

    I have a frame that is composed of several panels. One of those is a DisplayPanel for displaying drawings. I use CardLayout to display the drawings. Therefore, the uses can click on the next/previous button to look at the next/previous card of drawing that is shown in the displayPanel. I test the "next" button, and it works okay.
    However, when I click on the "previous button", it DOES NOT show the exact drawings that I have before navigating to the next card.
    Does anyone have any clue on why this will happen and how can I fix that?
    Here's the skeleton of my coding:
    public class drawMap extends JPanel
         // variable declaration
         public drawMap(Vector mapData, int index)
         public Dimension getPreferredSize()
              return new Dimension(width, height);
         public void paintComponent(Graphics g)
              // loop throught the mapData vector starting from the
              //       given index that is got from the constructor
              // draw two rows
    public class DisplayPanel extends JPanel implements ActionListener
         private JButton previousButton, nextButton;
         private JPanel allMaps = new JPanel(new CardLayout());
         DisplayPanel()
              add(mapPanel);
              add(buttonPanel);
         private JPanel mapPanel()
              int i=0, cardIndex=0;
              while (i < mapData.size())
                   DrawMap map = new DrawMap(mapData, i)
                   allMaps.add(map, String.valueOf(cardIndex));
                   i = findNextIndex(); // find the next index to start for the mapData
                   cardIndex++;
         private JPanel buttonPanel()
              JPanel p = new JPanel();
              previousButton = new JButton("Previous");
              previousButton.addActionListener(this);
              nextButton = new JButton("Next");
              nextButton.addActionListener(this);
              p.add(previousButton);
              p.add(nextButton);
              return p;
         private int findNextIndex()
              // find the next index to start
         public void actionPerformed(ActionEvent event)
              Object source = event.getSource();
              CardLayout cards = (CardLayout) (allMaps.getLayout());
              if (source == previousButton)
                   cards.previous(allMaps);
              else if (source == nextButton)
                   cards.next(allMaps);
    }

    Sorry for the long code. I minimize it as much as I can.
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import java.awt.*;
    public class MapFrame extends JPanel
        private SelectionList selection;
        private DisplayPanel display;
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
        private static void createAndShowGUI()
            JFrame frame = new JFrame("Drawing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new MapFrame());
            frame.pack();
            frame.setVisible(true);
            frame.setSize(500,500);
            frame.setLocationRelativeTo(null);
        public void setSelection(int c)
             display.setChoice(c);
        public MapFrame ()
            setLayout(new BorderLayout(5, 5));
            setPreferredSize(new Dimension(200, 200));
            add(display = new DisplayPanel(), BorderLayout.CENTER);
            add(selection = new SelectionList(this), BorderLayout.WEST);     
    class SelectionList extends JPanel implements ActionListener
         private MapFrame parent;
         private JRadioButton circleRadio, rectRadio;
         private static final int CIRCLE = 1;
         private static final int RECT = 2;
         public SelectionList(MapFrame theParent)
              this.parent = theParent;
              add(radioButton());
         public JPanel radioButton()
              JPanel p = new JPanel(new GridLayout(2,1));     
              circleRadio = new JRadioButton("Circle");
              rectRadio = new JRadioButton("Rect");
              circleRadio.addActionListener(this);
              rectRadio.addActionListener(this);
              ButtonGroup group = new ButtonGroup();
              group.add(circleRadio);
              group.add(rectRadio);
              p.add(circleRadio);
              p.add(rectRadio);
              return p;
         public void actionPerformed(ActionEvent event)
              Object source = event.getSource();
              if (source == circleRadio)
                   parent.setSelection(CIRCLE);
              else if (source == rectRadio)
                   parent.setSelection(RECT);
    class DisplayPanel extends JPanel implements ActionListener
         private static final int CIRCLE = 1;
         private static final int RECT = 2;
        private JButton previousButton, nextButton;
         private int choice = 0;
         private JPanel allMaps = new JPanel(new CardLayout());
         int [] list = {200, 100, 150, 100, 80, 125, 240};
         public DisplayPanel()
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.anchor = GridBagConstraints.CENTER;
              gbc.insets = new Insets (5, 5, 5, 5);
              gbc.fill = GridBagConstraints.NONE;
              gbc.gridx = 0; gbc.gridy = 0; add(mapPanel(), gbc);
              gbc.gridy = 1; add(buttonPanel(), gbc);
         public void setChoice(int i)
              if (i == CIRCLE)
                   choice = CIRCLE;
              else
                   choice = RECT;
              mapPanel();
         private JPanel mapPanel()
              allMaps.removeAll();
              allMaps.validate();
              int i = 0;
              int cardIndex = 0;
              if (choice != 0)
                   while (i < list.length)
                        DrawMap map = new DrawMap(choice, i, list);
                        allMaps.add(map, String.valueOf(cardIndex));
                        int temp = findNextStart(map, i);
                        i = temp;                         
                        cardIndex++;
                   allMaps.validate();                    
              else
                   DrawMap map = new DrawMap(choice, i, null);
                   allMaps.add(map, String.valueOf(0));
                   allMaps.validate();
              return allMaps;
         public int findNextStart(DrawMap map, int i)
              int x = 0;
              int index = i;
              while (x <= 1)
                   int curXPosition = 0;
                   int nextLength = 0;
                   while (curXPosition + nextLength <= 400 && index < list.length)
                        int length = list[index];          
                        curXPosition += length;
                        index++;
                        if (index < list.length)
                             nextLength = list[index];
                   x++;
              return index;
         private JPanel buttonPanel()
              JPanel p = new JPanel();
              previousButton = new JButton("Previous");     
              previousButton.addActionListener(this);
              nextButton = new JButton("Next");     
              nextButton.addActionListener(this);
              p.add(previousButton);
              p.add(nextButton);
              return p;
         public void actionPerformed(ActionEvent event)
              Object source = event.getSource();
              CardLayout cards = (CardLayout) (allMaps.getLayout());
              if (source == previousButton)
                   cards.previous(allMaps);
              else if (source == nextButton)
                   cards.next(allMaps);
    class DrawMap extends JPanel
         private static final int D_WIDTH = 400;
         private static final int D_HEIGHT = 400;
         private static final int CIRCLE = 1;
         private static final int RECT = 2;
         int width, height;
         int choice;
         int [] list;
         int index;
         public DrawMap(int c, int counter, int[] l)
              width = D_WIDTH;
              height = D_HEIGHT;
              choice = c;
              index = counter;
              list = l;
         public Dimension getPreferredSize()
              return new Dimension(width, height);
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2d = (Graphics2D) g;
              if (list != null)
                   int x = 0;
                   while (x <= 1)
                        int gridYLine = (height/2) * x;
                        int curXPosition = 0;
                        int nextLength = 0;
                        while (curXPosition + nextLength <= width && index < list.length)
                             int length = list[index];
                             if (choice == CIRCLE)
                                  g2d.drawOval(curXPosition, gridYLine, length, length);
                             else
                                  g2d.drawRect(curXPosition, gridYLine,length, length);
                             curXPosition += length;
                             index++;
                             if (index < list.length)
                                  nextLength = list[index];
                        x++;
    }

  • CardLayout-Problem

    package swing;
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.*;
    public class Basic extends JFrame implements ItemListener {
         JPanel cards;
         public Basic()
              super("Title");
              JPanel panel = new JPanel();
              JPanel comboPanel = new JPanel();
              String comboItems[] = {"First_Panel","SecondPanel"};
              JComboBox combo = new JComboBox(comboItems);
              cards = new JPanel(new CardLayout());
              JPanel card_1 = new JPanel();
              card_1.add(new JButton("Butotn"));
              JPanel card_2 = new JPanel();
              card_2.add(new JTextField("TextField"));
              cards.add(card_1,"First_Panel");
              cards.add(card_2,"SecondPanel");
              combo.addItemListener(this);
              comboPanel.add(combo);
              combo.setEditable(false);
              panel.add(comboPanel,BorderLayout.PAGE_START);
              panel.add(cards,BorderLayout.CENTER);
              add(getContentPane().add(panel));
              setVisible(true);
              pack();
         public static void main(String args[])
              new Basic();
         public void itemStateChanged(ItemEvent evt) {
              CardLayout c = (CardLayout)cards.getLayout();
              c.show(cards,(String)evt.getItem());
    }When i do run the above code, i do not get cards at the center although i have specified panel.add(cards,BorderLayout.CENTER);
    Moreover cards.getLayout returns LayoutManager hence casting required, but i cant understand the reason why is it so, since i have specified cards with CardLayout in the constructor

    OK, I now understand your query.
    (see if I can get the explanation correct)
    LayoutManager is an interface, so only one method needs to be written for getLayout().
    if the method was to return CardLayout
    public CardLayout getlayout()...
    you would need a method written for all the LayoutManagers, then a rewrite
    for future LayoutManagers.
    as is, its' just the one method, with a cast.
    Hope there is some accuracy in this

  • A CardLayout problem--wrong parent for CardLayout

    I am trying to use CardLayout so that only one of the several panels I crete will be display at a time. However, JBuilder gives me the "java.lang.IllegalArgumentException:wrong parent for CardLayout
    "error. What's wrong?
    package nestedlayouts;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class Frame1 extends JFrame implements ActionListener{
    CardLayout cl = new CardLayout();
    JPanel cardPanel = new JPanel(cl);
    JPanel welcomePane;
    JPanel balancePane;
    JButton balanceButton = new JButton();
    JButton welcomeButton = new JButton();
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch (Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    Container content = getContentPane();
    content.add(cardPanel );
    welcomePane = new JPanel();
    welcomePane.setLayout(null);
    welcomeButton.setText("Welcome");
    welcomeButton.setBounds(new Rectangle(90, 180, 196, 56));
    welcomeButton.addActionListener(this);
    welcomePane.setName("welcomePane");
    cardPanel.add("welcomePane",welcomePane);
    welcomePane.add(welcomeButton, null);
    balanceButton.setText("ShowBalance");
    balanceButton.setBounds(new Rectangle(154, 181, 196, 56));
    balanceButton.addActionListener(this);
    balancePane = new JPanel();
    balancePane.setLayout(null);
    balancePane.add(balanceButton, null);
    balancePane.setName("balancePane");
    cardPanel.add("balancePane",balancePane);
    this.setSize(new Dimension(509, 333));
    this.setTitle("ATM");
    show();
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    public void actionPerformed(ActionEvent e) {
    if ( ( (JButton) e.getSource()).getText().equals("ShowBalance")) {
    showPanel(1);
    else if ( ( (JButton) e.getSource()).getText().equals("Welcome")){
    showPanel(2);
    private void showPanel(int num) {
    if (num == 2) {
    cl.show(balancePane, "balancePane");
    else if (num == 1){
    }

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //import com.borland.jbcl.layout.*;
    public class bigeyes extends JFrame implements ActionListener{
      CardLayout cl = new CardLayout();
      JPanel cardPanel = new JPanel(cl);
      JPanel welcomePane;
      JPanel balancePane;
      JButton balanceButton = new JButton();
      JButton welcomeButton = new JButton();
      //Construct the frame
      public bigeyes() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        catch (Exception e) {
          e.printStackTrace();
      //Component initialization
      private void jbInit() throws Exception {
        Container content = getContentPane();
        content.add(cardPanel );
        welcomePane = new JPanel();
        welcomePane.setLayout(null);
        welcomeButton.setText("Welcome");
        welcomeButton.setBounds(new Rectangle(90, 180, 196, 56));
        welcomeButton.addActionListener(this);
        welcomePane.setName("welcomePane");
        cardPanel.add("welcomePane",welcomePane);
        welcomePane.add(welcomeButton, null);
        balanceButton.setText("ShowBalance");
        balanceButton.setBounds(new Rectangle(154, 181, 196, 56));
        balanceButton.addActionListener(this);
        balancePane = new JPanel();
        balancePane.setLayout(null);
        balancePane.add(balanceButton, null);
        balancePane.setName("balancePane");
        cardPanel.add("balancePane",balancePane);
        this.setSize(new Dimension(509, 333));
        this.setTitle("ATM");
        show();
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
      public void actionPerformed(ActionEvent e) {
        if ( ( (JButton) e.getSource()).getText().equals("ShowBalance")) {
          showPanel(1);
        else if ( ( (JButton) e.getSource()).getText().equals("Welcome")){
          showPanel(2);
      private void showPanel(int num) {
        if (num == 2) {
          // cardPanel is the parent, balancePane is the child (card)
          // that you added to the parent and now want to show
          // key: parent,     card name
          cl.show(cardPanel, "balancePane");  // error was pointing to this line
        else if (num == 1){
      public static void main(String[] args) {
        new bigeyes();
    }

  • Problem with JPanel, CardLayout and Applets

    Hello All,
    I have a JPanel with a CardLayout as layout manager. In this JPanel i'm gonna show a few applets.
    My problem is when i'm showing an applet for second time and try to click a button it does nothing... I think the action method is not called again...
    How can i solve this?
    Thanks in advance ; )

    Here is a few parts of my code...
    public class InitAll{
    JPanel cards = new JPanel( new CardLayout() );
    JComboBox selector = new JComboBox();
    Object objetosV[][] ={
         {"Ventas",venta.class},
         {"Compras",compras.class}, //These are applets.
         {"Traspasos",traspasos.class},
         {"Facturas",factura.class},
    public void load( Applet app ){
    cards.removeAll();
    selector.removeAll();
    cards.add( "Entrada", app );
    selector.addItem( "Entrada" );
    for ( int i=0; i < objetosV.length; i++ ){
         selector.addItem( (String)objetosV[0] );
         Applet temp=createPanel( ( Class ) objetosV[i][1] );
         temp.setSize( 800,750 );
         cards.add( ( String ) objetosV[i][0], temp );
    public void itemStateChanged(ItemEvent e) {
    ((CardLayout)cards.getLayout()).show(cards, selector.getSelectedItem().toString() );
    Applet tmp = (Applet)cards.getComponent(selector.getSelectedIndex() );
    tmp.start();
    After i show for second time an Applet and select a button from it. the button does nothing...
    Thanks...

  • Java Applet Panel problems with CardLayout

    Hi, I have a problem a I have been stucked for 2 days.
    I created 3 Panels to use with CardLayout. I would switch between those 3 panels depending on user interaction. I have some textfields and text areas on the 2nd and 3rd Panel. On the 1st panel, I would like to use g.drawstring to write some stuff on that panel, but the words would be blocked off if it goes to where the components are on the other panels.
    Thanks.

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    public class CardTest extends Applet
        Panel panel;
        CardLayout cards;
        public void init()
        {   cards = new CardLayout();
            panel = new Panel(cards);
            panel.add("one", new GraphicPanel());
            panel.add("two", getPanel("panel two"));
            panel.add("three", getPanel("panel three"));
            setLayout(new BorderLayout());
            add(getNavPanel(), "North");
            add(panel);
        private Panel getNavPanel()
            final Button
                last = new Button("last"),
                next = new Button("next");
            ActionListener l = new ActionListener()
                public void actionPerformed(ActionEvent e)
                    Button button = (Button)e.getSource();
                    if(button == last)
                        cards.previous(panel);
                    if(button == next)
                        cards.next(panel);
            last.addActionListener(l);
            next.addActionListener(l);
            Panel panel = new Panel();
            panel.add(last);
            panel.add(next);
            return panel;
        private Panel getPanel(String s)
            Panel panel = new Panel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weighty = 1.0;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(new Button("button"), gbc);
            panel.add(new TextArea(s, 8, 16), gbc);
            return panel;
        public static void main(String[] args)
            Applet applet = new CardTest();
            Frame f = new Frame();
            f.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
            f.add(applet);
            f.setSize(400,400);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    class GraphicPanel extends Panel
        Font font;
        String text;
        final int PAD = 25;
        public GraphicPanel()
            font = new Font("lucida bright regular", Font.PLAIN, 22);
            text = "Hello World";
        public void paint(Graphics g)
            super.paint(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            int dia = Math.min(w,h)/6;
            g2.setPaint(Color.blue);
            g2.drawLine(PAD, PAD, w - PAD, PAD);
            g2.drawLine(PAD, h - PAD, w - PAD, h - PAD);
            g2.setPaint(Color.green.darker());
            g2.drawOval(w/2 - dia/2, h*2/3, dia, dia);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            float width = (float)font.getStringBounds(text, frc).getWidth();
            LineMetrics lm = font.getLineMetrics(text, frc);
            float x = (w - width)/2;
            float y = (h + lm.getHeight())/2 -lm.getDescent();
            g2.setPaint(Color.black);
            g2.drawString(text, x, y);
    }

  • Problem with CardLayout

    I ve got a JFrame object and i want to put in it a JMenuBar and a CardLayout that contains two JPanel.
    1. Is it possible to do that
    3. how to do it.(I have already created my JMenuBar in my JFrame)

    Ok this is my source code.
    my problem is to insert a cardlayout it dosen't seem to work.
    Can you help me please.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.TitledBorder ;
    public class Frame1 extends javax.swing.JFrame
         Panel_Moteur jPanel1 = new Panel_Moteur();
         javax.swing.JMenuBar jMenuBar1 = new javax.swing.JMenuBar();
         javax.swing.JMenu jMenuFichier = new javax.swing.JMenu();
         javax.swing.JSeparator jMenuFichierSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuFichierQuitter = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuConfiguration = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuConfigurationMoteur = new javax.swing.JMenuItem();
         javax.swing.JSeparator jMenuConfigurationSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuConfigurationHoraire = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuProgrammes = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuProgrammesAjouter = new javax.swing.JMenuItem();
         javax.swing.JMenuItem jMenuProgrammesModifier = new javax.swing.JMenuItem();
         javax.swing.JMenuItem jMenuProgrammesSupprimer = new javax.swing.JMenuItem();
         javax.swing.JSeparator jMenuProgrammesSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuProgrammesVisualiser = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuAcquisition = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuAcquisitionCapture = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuReconstitution = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuReconstitutionImageGlobale = new javax.swing.JMenuItem();
         JPanel cards = new JPanel();
         CardLayout cardlayout = new CardLayout() ;
         public Frame1() {
         public void initComponents() throws Exception
              cards.setSize(new java.awt.Dimension(930, 830));
              cards.setLocation(new java.awt.Point(0, 40));
    cards.setLayout(cardlayout);
              cards.add(jPanel1,"t");
              jMenuBar1.setVisible(true);
              jMenuFichier.setVisible(true);
              jMenuFichier.setText("Fichier");
              jMenuFichierSeparator1.setVisible(true);
              jMenuFichierQuitter.setVisible(true);
              jMenuFichierQuitter.setText("Quitter");
              jMenuConfiguration.setVisible(true);
              jMenuConfiguration.setText("Configuration");
              jMenuConfigurationMoteur.setVisible(true);
              jMenuConfigurationMoteur.setText("Moteur");
              jMenuConfigurationSeparator1.setVisible(true);
              jMenuConfigurationHoraire.setVisible(true);
              jMenuConfigurationHoraire.setText("Horaire");
              jMenuProgrammes.setVisible(true);
              jMenuProgrammes.setText("Programmes");
              jMenuProgrammesAjouter.setVisible(true);
              jMenuProgrammesAjouter.setText("Ajouter");
              jMenuProgrammesModifier.setVisible(true);
              jMenuProgrammesModifier.setText("Modifier");
              jMenuProgrammesSupprimer.setVisible(true);
              jMenuProgrammesSupprimer.setText("Supprimer");
              jMenuProgrammesSeparator1.setVisible(true);
              jMenuProgrammesVisualiser.setVisible(true);
              jMenuProgrammesVisualiser.setText("Visualiser");
              jMenuAcquisition.setVisible(true);
              jMenuAcquisition.setText("Acquisition");
              jMenuAcquisitionCapture.setVisible(true);
              jMenuAcquisitionCapture.setText("Capture");
              jMenuReconstitution.setVisible(true);
              jMenuReconstitution.setText("Reconstitution");
              jMenuReconstitutionImageGlobale.setVisible(true);
              jMenuReconstitutionImageGlobale.setText("Image Globale");
              setLocation(new java.awt.Point(150, 70));
              setResizable(false);
              setJMenuBar(jMenuBar1);
              getContentPane().setLayout(null);
              setTitle("ProjetAutoroot.Frame1");
              jMenuBar1.add(jMenuFichier);
              jMenuBar1.add(jMenuConfiguration);
              jMenuBar1.add(jMenuProgrammes);
              jMenuBar1.add(jMenuAcquisition);
              jMenuBar1.add(jMenuReconstitution);
              jMenuFichier.add(jMenuFichierSeparator1);
              jMenuFichier.add(jMenuFichierQuitter);
              jMenuConfiguration.add(jMenuConfigurationMoteur);
              jMenuConfiguration.add(jMenuConfigurationSeparator1);
              jMenuConfiguration.add(jMenuConfigurationHoraire);
              jMenuProgrammes.add(jMenuProgrammesAjouter);
              jMenuProgrammes.add(jMenuProgrammesModifier);
              jMenuProgrammes.add(jMenuProgrammesSupprimer);
              jMenuProgrammes.add(jMenuProgrammesSeparator1);
              jMenuProgrammes.add(jMenuProgrammesVisualiser);
              jMenuAcquisition.add(jMenuAcquisitionCapture);
              jMenuReconstitution.add(jMenuReconstitutionImageGlobale);
              getContentPane().add(cards);
              setSize(new java.awt.Dimension(941, 923));
              jMenuFichierQuitter.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        jMenuFichierQuitterActionPerformed(e);
              jMenuConfigurationMoteur.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        jMenuConfigurarionMoteurActionPerformed(e);
              addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        thisWindowClosing(e);
         private boolean mShown = false;
         public void addNotify() {
              super.addNotify();
              if (mShown)
                   return;
              // resize frame to account for menubar
              JMenuBar jMenuBar = getJMenuBar();
              if (jMenuBar != null) {
                   int jMenuBarHeight = jMenuBar.getPreferredSize().height;
                   Dimension dimension = getSize();
                   dimension.height += jMenuBarHeight;
                   setSize(dimension);
              mShown = true;
         // Close the window when the close box is clicked
         void thisWindowClosing(java.awt.event.WindowEvent e) {
              setVisible(false);
              dispose();
              System.exit(0);
         public void jMenuFichierQuitterActionPerformed(java.awt.event.ActionEvent e) {
              setVisible(false);
              dispose();
              System.exit(0);
         public void jMenuConfigurarionMoteurActionPerformed (java.awt.event.ActionEvent e)
              System.out.println("bonjour") ;
              CardLayout cl = (CardLayout)(cards.getLayout());
              cl.show(cards,"t");
         public void jRadioButton1StateChanged(javax.swing.event.ChangeEvent e) {
         public void jRadioButton2StateChanged(javax.swing.event.ChangeEvent e) {
         public void jRadioButton9StateChanged(javax.swing.event.ChangeEvent e) {
    }

  • Problem moving through CardLayout

    Hi,
    I have been unable to find any solid examples of CardLayout, so I have been using some code I found in this forum. I'm getting hung up on how to move forward or backwards through the cards. I know it is myCard.next but for some reason I'm getting hung up on which card I should be referencing and how to associate that card with the code. Perhaps someone could spot the error...
    Thanks,
    Steve
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    class Interface extends JFrame {
         private dataPanel screenvar;
    //     private questionPaneOne abcdef;
         private JTextArea msgout;
         JPanel cardPane;
         Interface () {
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new JPanel();     // for CardLayout
              CardLayout questions = new CardLayout();
              cardPane.setLayout(questions);
              cardPane.setBorder(BorderFactory.createCompoundBorder(
                                              BorderFactory.createMatteBorder(
                                                              1,1,2,2,Color.blue),
                                    BorderFactory.createEmptyBorder(5,5,5,5)));
              cardTestOnePane     cardOne = new cardTestOnePane();
              cardTestTwoPane     cardTwo = new cardTestTwoPane();
              cardPane.add("questionOne", cardOne);
              cardPane.add("questionTwo", cardTwo);
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              buttonPanel commandButtons = new buttonPanel(screenvar, msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));   // row, col, hgap, vgap
              pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30)); //top, left, bottom, right
              pane.add(cardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
    class updateDataFields implements ActionListener {     // 400
         private dataPanel abc;
         private JTextArea msg;
         int count = 0;
         public updateDataFields(dataPanel xyz, JTextArea msgout) {     // 100
              abc = xyz;
              msg = msgout;
         }     // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        btnNextPressed();
                   }     // 300
         }     // 200
         private void btnNextPressed() {     // 500
    // problem here
              cardPane.next(cardTwo);
              }     // 500
    }     // 400
    class buttonPanel extends JPanel {     // 200   Similar to ButtonPanel in Duke's Bakery
         public buttonPanel(dataPanel xyz, JTextArea msgout) {     // 100
              GridLayout actionGrid = new GridLayout(1, 1, 5, 15); // row, col, hgap, vgap
              setLayout(actionGrid);                    // different than panex.setLayout(xgrid);
              JButton buttonTest = new JButton("TestMe");
              buttonTest.setMnemonic('T');
              buttonTest.addActionListener( new updateDataFields( xyz, msgout ));
              add(buttonTest);
         }     // 100
    }     // 200
    class dataPanel extends JPanel {     // Similar to DataPanel in Duke's Bakery
         JLabel left1, left2, left3, right1, right2, right3;
         JTextField left01, left02, left03, right01, right02, right03;
        public dataPanel () {     // 1
              GridLayout grid = new GridLayout(3, 2, 5, 15); // row, col, hgap, vgap
              setLayout(grid);                    // different than panex.setLayout(xgrid);
              left1 = new JLabel("Left1");
              add(left1);
              left01 = new JTextField(0);
              add(left01);
              right1 = new JLabel("Right1");
              add(right1);
              right01 = new JTextField(0);
              add(right01);
    class cardTestOnePane extends JPanel {
         public cardTestOnePane() {
              GridLayout actionGrid1 = new GridLayout(2, 1, 5, 15); // row, col, hgap, vgap
              setLayout(actionGrid1);
              JLabel cardNumberOne = new JLabel("Card Number One");
              JLabel cardNumberTwo = new JLabel("Card Number Two");
              add(cardNumberOne);
              add(cardNumberTwo);
    class cardTestTwoPane extends JPanel {
         public cardTestTwoPane() {
              GridLayout actionGrid1 = new GridLayout(2, 1, 5, 15); // row, col, hgap, vgap
              setLayout(actionGrid1);
              JLabel cardNumberThree = new JLabel("Card Number Three");
              JLabel cardNumberFour = new JLabel("Card Number Four");
              add(cardNumberThree);
              add(cardNumberFour);
    }

    When importing files Lightroom states:
    The following files were not imported because they could not be read.
    IMG_5551.CR2
    When deleting files in Lightroom it states:
    The file named 'IMG_6191.jpg' could not be moved to the Trash folder
    When moving files Lightroom shows the following error:
    File could not be moved to the selected destination.
    EDIT: it is only happening in a single folder/location (with a lot of foto's and subfolders). The rest seems to be working correctly. Strange and irritating.

  • Problems with actionListeners on CardLayout...Help Please

    I'm having a problem with my clear button on card2 in my code. When pressed it will not clear the data, and I don't see anything wrong with the code. Am I overlooking something? Please take a look at the long code I have posted and let me know what is going on with this if you could.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class BankGUI implements ItemListener
         JPanel cards;
         final String main = "Main menu";
         final String addCust = "Add a new customer";
         final String upCust = "Change a current customer's information";
         final String addAcct = "Add a new account";
         final String withdrawl = "Withdrawl monies from an account";
         final String deposit = "Deposit monies into an account";
         final String report = "Run report to show all accounts";
         JComboBox cb;
         JRadioButton savings, checking;
         JCheckBox yes, no;
         JLabel firstNameLabel, lastNameLabel, addressLabel, cityLabel, stateLabel,
              phoneLabel, customerNumbLabel, accountNumbLabel, depositLabel,
              accountTypeLabel, savingsProLabel, balanceLabel, withdrawlLabel;
         JTextField firstNameField, lastNameField, addressField, cityField,
              stateField, phoneField, customerNumbField, accountNumbField,
              depositField, accountTypeField, balanceField, withdrawlField;
         JButton submit1, submit3, submit4, submit5, submit6, clear, logoff, run, find,
               delete, update, runReport;
         JFrame f;
         String firstName;
         String lastName;
         String address;
         String city;
         String state;
         String phoneNumber;
         String customerNumber;
         Controller cont;
         Customer cust;
         public void addComponent(Container pane)
              JPanel comboBoxPane = new JPanel();
              String comboBoxItems[] = {main, addCust, upCust, addAcct,
                   withdrawl, deposit, report};
              JComboBox cb = new JComboBox(comboBoxItems);
              cb.setEditable(false);
              cb.addItemListener(this);
              comboBoxPane.add(cb);
              JPanel card1 = new JPanel(); //main menu
              logoff = new JButton("Logoff");
              logoff.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent l)
                        cont = new Controller();
                        cont.wrapUp();
              card1.add(logoff); //end main menu
              JPanel card2 = new JPanel(new GridLayout(0,4,1,1)); //add customer
              firstNameLabel = new JLabel("First Name:", SwingConstants.RIGHT);
              card2.add(firstNameLabel);
              firstNameField = new JTextField("", 10);
              card2.add(firstNameField);
              lastNameLabel = new JLabel("Last Name:", SwingConstants.RIGHT);
              card2.add(lastNameLabel);
              lastNameField = new JTextField("", 10);
              card2.add(lastNameField);
              addressLabel = new JLabel("Address:", SwingConstants.RIGHT);
              card2.add(addressLabel);
              addressField = new JTextField("", 10);
              card2.add(addressField);
              cityLabel = new JLabel("City:", SwingConstants.RIGHT);
              card2.add(cityLabel);
              cityField = new JTextField("", 10);
              card2.add(cityField);
              stateLabel = new JLabel("State:", SwingConstants.RIGHT);
              card2.add(stateLabel);
              stateField = new JTextField("", 10);
              card2.add(stateField);
              phoneLabel = new JLabel("Phone Number:", SwingConstants.RIGHT);
              card2.add(phoneLabel);
              phoneField = new JTextField("", 10);
              card2.add(phoneField);
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card2.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card2.add(customerNumbField);
              card2.add(new JLabel(""));
              card2.add(new JLabel(""));
              card2.add(new JLabel(""));
              submit1 = new JButton("Submit");
              /*submit1.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent s1)
                        firstName = firstNameField.getText();
                        lastName = lastNameField.getText();
                        address = addressField.getText();
                        city = cityField.getText();
                        state = stateField.getText();
                        phoneNumber = phoneField.getText();
                        customerNumber = customerNumbField.getText();
                        Customer cust = new Customer(firstName, lastName, address, city, state, phoneNumber, customerNumber);
                        System.out.println(cust.getFirstName());
              card2.add(submit1);
              clear = new JButton("Clear");
              clear.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent c)
                        firstNameField.setText("");
                        lastNameField.setText("");
                        addressField.setText("");
                        cityField.setText("");
                        stateField.setText("");
                        phoneField.setText("");
                        customerNumbField.setText("");
                        firstNameField.requestFocus();
              card2.add(clear); //end add customer
              JPanel card3 = new JPanel(new GridLayout(0,4,1,1)); //update customer
              card3.add(new JLabel(""));
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card3.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card3.add(customerNumbField);
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              find = new JButton("Find");
              card3.add(find);
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              firstNameLabel = new JLabel("First Name:", SwingConstants.RIGHT);
              card3.add(firstNameLabel);
              firstNameField = new JTextField("", 10);
              card3.add(firstNameField);
              lastNameLabel = new JLabel("Last Name:", SwingConstants.RIGHT);
              card3.add(lastNameLabel);
              lastNameField = new JTextField("", 10);
              card3.add(lastNameField);
              addressLabel = new JLabel("Address:", SwingConstants.RIGHT);
              card3.add(addressLabel);
              addressField = new JTextField("", 10);
              card3.add(addressField);
              cityLabel = new JLabel("City:", SwingConstants.RIGHT);
              card3.add(cityLabel);
              cityField = new JTextField("", 10);
              card3.add(cityField);
              stateLabel = new JLabel("State:", SwingConstants.RIGHT);
              card3.add(stateLabel);
              stateField = new JTextField("", 10);
              card3.add(stateField);
              phoneLabel = new JLabel("Phone Number:", SwingConstants.RIGHT);
              card3.add(phoneLabel);
              phoneField = new JTextField("", 10);
              card3.add(phoneField);
              card3.add(new JLabel(""));
              submit3 = new JButton("Save Changes");
              card3.add(submit3); //end update customer
              JPanel card4 = new JPanel(new GridLayout(0,4,1,1)); //add account
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card4.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card4.add(customerNumbField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card4.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card4.add(accountNumbField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              accountTypeLabel = new JLabel("Account Type:", SwingConstants.RIGHT);
              card4.add(accountTypeLabel);
              savings = new JRadioButton("Savings");
              card4.add(savings);
              checking = new JRadioButton("Checking");
              card4.add(checking);
              card4.add(new JLabel(""));
              depositLabel = new JLabel("Deposit Amount:", SwingConstants.RIGHT);
              card4.add(depositLabel);
              depositField = new JTextField("", 10);
              card4.add(depositField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              submit4 = new JButton("Submit");
              card4.add(submit4);//end add account
              JPanel card5 = new JPanel(new GridLayout(0,4,1,1)); //withdrawl
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card5.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card5.add(accountNumbField);
              card5.add(new JLabel(""));
              card5.add(new JLabel(""));
              withdrawlLabel = new JLabel("Withdrawl Amount:", SwingConstants.RIGHT);
              card5.add(withdrawlLabel);
              withdrawlField = new JTextField("", 10);
              card5.add(withdrawlField);
              card5.add(new JLabel(""));
              card5.add(new JLabel(""));
              submit5 = new JButton("Submit");
              card5.add(submit5);//end withdrawl
              JPanel card6 = new JPanel(new GridLayout(0,4,1,1)); //deposit
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card6.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card6.add(accountNumbField);
              card6.add(new JLabel(""));
              card6.add(new JLabel(""));
              depositLabel = new JLabel("Deposit Amount:", SwingConstants.RIGHT);
              card6.add(depositLabel);
              depositField = new JTextField("", 10);
              card6.add(depositField);
              card6.add(new JLabel(""));
              card6.add(new JLabel(""));
              submit6 = new JButton("Submit");
              card6.add(submit6);//end deposit
              JPanel card7 = new JPanel(); //run report
              card7.add(new JLabel(""));
              runReport = new JButton("Run Report");
              card7.add(runReport);//end report
              cards = new JPanel(new CardLayout());
              cards.add(card1, main);
              cards.add(card2, addCust);
              cards.add(card3, upCust);
              cards.add(card4, addAcct);
              cards.add(card5, withdrawl);
              cards.add(card6, deposit);
              cards.add(card7, report);
              pane.add(comboBoxPane, BorderLayout.PAGE_START);
              pane.add(cards);
         public void itemStateChanged(ItemEvent evt)
              CardLayout cl = (CardLayout)(cards.getLayout());
              cl.show(cards, (String)evt.getItem());
         public void createGUI()
              f = new JFrame("Bank of Sean");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              BankGUI bankGUI = new BankGUI();
              bankGUI.addComponent(f.getContentPane());
              f.pack();
              f.setVisible(true);
         public static void main(String[] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        BankGUI bankGUI = new BankGUI();
                        bankGUI.createGUI();
    }

    You have a generic problem that is illustrated by looking at your 'firstNameField'. You define just one 'firstNameField' variable and then allocated a value several times so that the content of 'firstNameField' add to card2 using
    card2.add(firstNameField);
    does not refer to the same object as is used in your action listener
    firstNameField.setText("");
    because in your card3 section you overwrite the original content ot the reference.
    You can fix this by sharing a Document e.g.
    Document doc = firstNameField.getDocument();
    firstNameField = new JTextField(doc, "", 10);
    card3.add(firstNameField);
    for each time a new field is reqired.

  • Problems with CardLayout

    Does anyone know how/if I should be overriding getLayoutAlignmentX (of LayoutManager2) in order to get the cards (panels) in my CardLayout to appear somewhere other than centred in the panel.
    My problem is that I don't seem to be able to alter the layout such that when the card is switched in it appears at the left of the panel in which it is contained.

    Overriding the layout manager should never be your first step.
    All a CardLayout does is make one of its contained panels visible. The layout manager may resize the panel, in which case it's the panel's own layout manager that's centering the content.
    The easiest (but ugliest) solution is simply to put another panel in the hierarchy, using FlowLayout. Something like this (uncompiled, untested):
        JPanel myCardPanel = new JPanel(new CardLayout());
        JPanel holder = new JPanel(new FlowLayout(FlowLayout.LEADING)));
        JPanel myRealPanel = // however you get it
        holder.add(myRealPanel);
        myCardPanel.add(holder,  "Top");As I said, this is a really hackish solution. A better solution is to arrange the layout on your real panel so that it can expand without changing the position of its components. Or lock its maximum size ot its preferred size.

  • NetBeans IDE 3.6 and CardLayout. Problem in actionPerformed.

    I'm trying to make a program that uses a JFrame as TopLevelContainer with CardLayout. The problem is that i dont know how to implement actionPerformed inorder to change between cards(JPanels).
    Here is a part of the hole program:
    getContentPane().add(jPanel2, "card3");
    pack();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    What should i add in the actionPerformed, inorder to achieve changing between two or more cards(JPanels)?
    Note:Every Panel has two navigation buttons.
    Here is the hole prog.
    public class JFrame extends javax.swing.JFrame {
        /** Creates new form JFrame */
        public JFrame() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jButton3 = new javax.swing.JButton();
            jButton4 = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.CardLayout());
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jPanel1.add(jButton1);
            jButton2.setText("jButton2");
            jPanel1.add(jButton2);
            getContentPane().add(jPanel1, "card2");
            jButton3.setText("jButton3");
            jPanel2.add(jButton3);
            jButton4.setText("jButton4");
            jPanel2.add(jButton4);
            getContentPane().add(jPanel2, "card3");
            pack();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new JFrame().show();
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        // End of variables declaration
    }

    Stop spamming.
    http://forum.java.sun.com/thread.jspa?threadID=617862

  • Problem with values of some components per card in CardLayout

    in card 1 i ask the user to enter the numbers (say the user entered, 55.3,62.5,73.2,86.7)
    parsed it, count the observations..
    now in card 2, i have a JComboBox of sample sizes from the numbers the user entered. (in the example, the JComboBox should show 1,2,3,4 since the sample size should be from 1 to "n" numbers of observations the user entered)
    the problem now is, how can i set the "n" for card 2 where the "n" will come from card 1?
    hope i made it clear... please help me...

    i think i figure it out already...
    i put the initiation of card 2 in a different method..
    whew!

  • Bouncing off the wall: Problems with passing/using pointers to classes

    I have a mostly completed "msPaint" (=assigment) program that is driving me nuts!!!
    1. First shape you draw doesn't appear.
    1.5 Draw a shape by clicking twice on Panel, can change shape, color, fill with what buttons you see.
    2. Subsequently only the newest shape appears. Using System.println(); it appears to be drawing as many shapes as it has made, but it doesn't.
    3. I owe much to anyone who helps me, here is complete code. Specifically will ask/reward you to reply to a diff link in which I have dukes, got no answer, and can't reallocate dukes. (=5)
    Thank you very much.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Prog4 extends JApplet implements ActionListener
         //private MainPanel drawingpanel;
         private JPanel top;
         private JPanel left;
         private JPanel bottom;
         private JPanel bottomleft,bottommiddletop,bottommiddle,bottomright;
         //top buttons created
         private JButton first,next,previous,last,help;
         //bottom buttons created
         private JButton custom;
         private JButton white,gray,red,purple,blue,green,yellow,orange;
         private JButton black,darkgray,darkred,darkpurple,darkblue,darkgreen,darkyellow,darkorange;
         private JButton rect,oval,line,solid,hollow,erase;
         private CardLayout drawingscreens;
         private MyShape [] shapes=new MyShape[10];
         private MyShape newshape=new MyShape();     
         private Data information;//=new Data(newshape, shapes);
         private MyPanel temp;//=new MyPanel(information);
         private int thiscard;
         public int x,y;
         //Holder Variable to hold info about shape to be drawn
         int shape;
         int fill;
         int draw;
         int tx,ty,bx,by;
         public void init()
              Container window=getContentPane();
                   window.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   //Top Button Setup
                   first=new JButton("First");
                   first.addActionListener(this);
                   first.setPreferredSize(new Dimension(100,40));
                   next=new JButton("Next");
                   next.addActionListener(this);
                   next.setPreferredSize(new Dimension(100,40));
                   previous=new JButton("Previous");
                   previous.addActionListener(this);
                   previous.setPreferredSize(new Dimension(100,40));
                   last=new JButton("Last");
                   last.addActionListener(this);
                   last.setPreferredSize(new Dimension(100,40));
                   help=new JButton("Help");
                   help.addActionListener(this);
                   help.setPreferredSize(new Dimension(100,40));
                   //TOP PANEL SETUP
                   top=new JPanel();
                   top.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   top.setPreferredSize(new Dimension(800,40));
                   top.setOpaque(true);
                   top.setBackground(Color.white);
                   top.add(first);
                   top.add(next);
                   top.add(previous);
                   top.add(last);
                   top.add(help);
                   window.add(top);
                   //Left Buttons Setup
                   rect=new JButton("Rectangle");
                   rect.setPreferredSize(new Dimension(100,40));
                   rect.addActionListener(this);
                   oval=new JButton("Oval");
                   oval.setPreferredSize(new Dimension(100,40));
                   oval.addActionListener(this);
                   line=new JButton("Line");
                   line.setPreferredSize(new Dimension(100,40));
                   line.addActionListener(this);
                   solid=new JButton("Solid");
                   solid.setPreferredSize(new Dimension(100,40));
                   solid.addActionListener(this);
                   hollow=new JButton("Hollow");
                   hollow.setPreferredSize(new Dimension(100,40));
                   hollow.addActionListener(this);
                   erase=new JButton("Erase");
                   erase.setPreferredSize(new Dimension(100,40));
                   erase.addActionListener(this);
                   //Left Panel Setup
                   left=new JPanel();
                   left.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   left.setPreferredSize(new Dimension(200,600));     
                   left.add(rect);
                   left.add(oval);
                   left.add(line);
                   left.add(solid);
                   left.add(hollow);
                   left.add(erase);
                   window.add(left);// FlowLayout.LEFT);
                   //Middle Setup
                   temp=new panel();
                   temp.setPreferredSize(new Dimension(600,600));
                   temp.setOpaque(true);
                   temp.setBackground(Color.red);
                   temp.addMouseListener(this);
                   window.add(temp);
                   //Panel Listener Initailization
                   for(int i=0; i<shapes.length; i++)
                        shapes=new MyShape();
                   information=new Data(newshape, shapes);
                   temp=new MyPanel(information);
                   Listener panelListener=new Listener(temp, newshape, information);
                   //shapes
                   window.add(temp);
                   temp.addMouseListener(panelListener);
                   //Bottom Buttons Setup
                   int bsize=20; //Int for horz/vert size of buttons
                   //Left Setup, creates a JPanel which displays the current color
                   bottomleft=new JPanel();
                   bottomleft.setPreferredSize(new Dimension(2*bsize,2*bsize));
                   bottomleft.setLayout(new FlowLayout(0,0, FlowLayout.LEFT));
                   bottomleft.setOpaque(true);
                   //Middle Setup creates buttons for each pregenerated color in the top row
                   black=new JButton();
                   black.setPreferredSize(new Dimension(bsize,bsize));
                   black.setOpaque(true);
                   black.setBackground(new Color(0,0,0));
                   black.addActionListener(this);
                   darkgray=new JButton();
                   darkgray.setPreferredSize(new Dimension(bsize,bsize));
                   darkgray.setOpaque(true);
                   darkgray.setBackground(new Color(70,70,70));
                   darkgray.addActionListener(this);
                   darkred=new JButton();
                   darkred.setPreferredSize(new Dimension(bsize,bsize));
                   darkred.setOpaque(true);
                   darkred.setBackground(new Color(180,0,0));
                   darkred.addActionListener(this);
                   darkpurple=new JButton();
                   darkpurple.setPreferredSize(new Dimension(bsize,bsize));
                   darkpurple.setOpaque(true);
                   darkpurple.setBackground(new Color(185,0,185));
                   darkpurple.addActionListener(this);
                   darkblue=new JButton();
                   darkblue.setPreferredSize(new Dimension(bsize,bsize));
                   darkblue.setOpaque(true);
                   darkblue.setBackground(new Color(0,0,150));
                   darkblue.addActionListener(this);
                   darkgreen=new JButton();
                   darkgreen.setPreferredSize(new Dimension(bsize,bsize));
                   darkgreen.setOpaque(true);
                   darkgreen.setBackground(new Color(0,140,0));
                   darkgreen.addActionListener(this);
                   darkyellow=new JButton();
                   darkyellow.setPreferredSize(new Dimension(bsize,bsize));
                   darkyellow.setOpaque(true);
                   darkyellow.setBackground(new Color(176,176,0));
                   darkyellow.addActionListener(this);
                   darkorange=new JButton();
                   darkorange.setPreferredSize(new Dimension(bsize,bsize));
                   darkorange.setOpaque(true);
                   darkorange.setBackground(new Color(170,85,0));
                   darkorange.addActionListener(this);
                   //Adds each button to a Panel
                   bottommiddletop=new JPanel();
                   bottommiddletop.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   bottommiddletop.setPreferredSize(new Dimension(8*bsize,bsize));
                   bottommiddletop.add(black);
                   bottommiddletop.add(darkgray);
                   bottommiddletop.add(darkred);
                   bottommiddletop.add(darkpurple);
                   bottommiddletop.add(darkblue);
                   bottommiddletop.add(darkgreen);
                   bottommiddletop.add(darkyellow);
                   bottommiddletop.add(darkorange);     
                   //Bottom Middle Creates bottom row of colors like top
                   white=new JButton();
                   white.setPreferredSize(new Dimension(bsize,bsize));
                   white.setOpaque(true);
                   white.setBackground(new Color(255,255,255));
                   white.addActionListener(this);
                   gray=new JButton();
                   gray.setPreferredSize(new Dimension(bsize,bsize));
                   gray.setOpaque(true);
                   gray.setBackground(new Color(192,192,192));
                   gray.addActionListener(this);
                   red=new JButton();
                   red.setPreferredSize(new Dimension(bsize,bsize));
                   red.setOpaque(true);
                   red.setBackground(new Color(255,0,0));
                   red.addActionListener(this);
                   purple=new JButton();
                   purple.setPreferredSize(new Dimension(bsize,bsize));
                   purple.setOpaque(true);
                   purple.setBackground(new Color(213,0,213));
                   purple.addActionListener(this);
                   blue=new JButton();
                   blue.setPreferredSize(new Dimension(bsize,bsize));
                   blue.setOpaque(true);
                   blue.setBackground(new Color(0,0,255));
                   blue.addActionListener(this);
                   green=new JButton();
                   green.setPreferredSize(new Dimension(bsize,bsize));
                   green.setOpaque(true);
                   green.setBackground(new Color(0,255,0));
                   green.addActionListener(this);
                   yellow=new JButton();
                   yellow.setPreferredSize(new Dimension(bsize,bsize));
                   yellow.setOpaque(true);
                   yellow.setBackground(new Color(255,255,0));
                   yellow.addActionListener(this);
                   orange=new JButton();
                   orange.setPreferredSize(new Dimension(bsize,bsize));
                   orange.setOpaque(true);
                   orange.setBackground(new Color(244,122,0));
                   orange.addActionListener(this);
                   //Attaches buttons to a panel
                   bottommiddle=new JPanel();
                   bottommiddle.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   bottommiddle.setPreferredSize(new Dimension(8*bsize,bsize));
                   bottommiddle.add(white);
                   bottommiddle.add(gray);
                   bottommiddle.add(     red);
                   bottommiddle.add(purple);
                   bottommiddle.add(blue);
                   bottommiddle.add(green);
                   bottommiddle.add(yellow);
                   bottommiddle.add(orange);     
                   //Creates middle panel for bottom
                   bottom=new JPanel();
                   bottom.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   bottom.setPreferredSize(new Dimension(8*bsize,2*bsize));
                   bottom.add(bottommiddletop);
                   bottom.add(bottommiddle);               
                   //This is for a button on buttom right to make custom colors.
                   //Right Setup creates a button which allows you to make your own color
                   custom=new JButton("More");
                   custom.setPreferredSize(new Dimension(4*bsize,2*bsize));
                   custom.setOpaque(true);
                   bottomright=new JPanel();
                   bottomright.setLayout(new FlowLayout(0,0,FlowLayout.LEFT));
                   bottomright.setPreferredSize(new Dimension(4*bsize,2*bsize));
                   bottomright.add(custom);
                   //The Panel containing current color is added first
                   //Then the two colors panels are added
                   //Then the panel with a custom button is added
                   window.add(bottomleft);
                   window.add(bottom);
                   window.add(bottomright);
         public void actionPerformed(ActionEvent e)
              //Buttons to change colors
              if(e.getSource()==black)
                   bottomleft.setBackground(new Color(0,0,0));
                   newshape.setColor(0,0,0);
              if(e.getSource()==darkgray)
                   bottomleft.setBackground(new Color(70,70,70));
                   newshape.setColor(70,70,70);
              if(e.getSource()==darkred)
                   bottomleft.setBackground(new Color(180,0,0));
                   newshape.setColor(180,0,0);
              if(e.getSource()==darkpurple)
                   bottomleft.setBackground(new Color(185,0,185));
                   newshape.setColor(185,0,185);
              if(e.getSource()==darkblue)
                   bottomleft.setBackground(new Color(0,0,150));
                   newshape.setColor(0,0,150);
              if(e.getSource()==darkgreen)
                   bottomleft.setBackground(new Color(0,140,0));
                   newshape.setColor(0,140,0);
              if(e.getSource()==darkyellow)
                   bottomleft.setBackground(new Color(176,176,0));
                   newshape.setColor(176,176,0);
              if(e.getSource()==darkorange)
                   bottomleft.setBackground(new Color(170,85,0));
                   newshape.setColor(170,85,0);
              if(e.getSource()==white)
                   bottomleft.setBackground(new Color(255,255,255));
                   newshape.setColor(255,255,255);
              if(e.getSource()==blue)
                   bottomleft.setBackground(new Color(0,0,255));
                   newshape.setColor(0,0,255);
              if(e.getSource()==red)
                   bottomleft.setBackground(new Color(255,0,0));
                   newshape.setColor(255,0,0);
              if(e.getSource()==green)
                   bottomleft.setBackground(new Color(0,255,0));
                   newshape.setColor(0,255,0);
              if(e.getSource()==purple)
                   bottomleft.setBackground(new Color(213,0,213));
                   newshape.setColor(213,0,213);
              if(e.getSource()==yellow)
                   bottomleft.setBackground(new Color(255,255,0));
                   newshape.setColor(255,255,0);
              if(e.getSource()==orange)
                   bottomleft.setBackground(new Color(244,122,0));
                   newshape.setColor(244,122,0);
              if(e.getSource()==gray)
                   bottomleft.setBackground(new Color(192,192,192));
                   newshape.setColor(192,192,192);
              //Code for setting shape to draw
              if(e.getSource()==rect)
                   setShapes();
                   rect.setBackground(Color.blue);               
                   newshape.setShape(1);
              if(e.getSource()==line)
                   setShapes();
                   newshape.setShape(0);
                   line.setBackground(Color.blue);
              if(e.getSource()==oval)
                   setShapes();
                   newshape.setShape(2);
                   oval.setBackground(Color.blue);
              //Code for setting to fill or not
              if(e.getSource()==solid)
                   solid.setBackground(Color.blue);
                   hollow.setBackground(Color.gray);
                   newshape.setFill(1);
              if(e.getSource()==hollow)
                   hollow.setBackground(Color.blue);
                   solid.setBackground(Color.gray);
                   newshape.setFill(0);
         public void setShapes()
              rect.setBackground(Color.gray);
              oval.setBackground(Color.gray);
              line.setBackground(Color.gray);
    class Data
         private MyShape newshape;
         private MyShape [] shapes;
         public Data(MyShape a, MyShape [] b)
              newshape=a;
              shapes=b;
         public void drawShapes(Graphics g)
              drawAllShapes(g);
         public void sortShapes()
              for(int t=8; t>=0; t--)
                   shapes[t+1]=shapes[t];
              shapes[0]=newshape;
              System.out.println("Shapes Sorted");
         public void drawAllShapes(Graphics g)
              newshape.reset(true);
              for(int i=9; i>=0; i--)
                   shapes[i].drawShape(g);
              System.out.println("Shapes Drawn??");
    class MyPanel extends JPanel
         private Data information;
         public MyPanel(Data a)
              information=a;
              setPreferredSize(new Dimension(600,600));
              setBackground(Color.blue);
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              information.drawShapes(g);
    class Listener extends MouseAdapter
         int x,y;
         private int [] loc=new int[4];
         int horzL, vertL;
         private boolean clicked=false;
         private boolean sortonce;
         private MyPanel temp;
         private MyShape newshape;
         private Data information;
         private int xt,yt,xl,yl;
         public Listener(MyPanel d, MyShape b, Data c)
              temp=d;
              newshape=b;          
              information=c;
         public void mouseClicked(MouseEvent e)
              if(clicked==false)
                   x=e.getX();
                   y=e.getY();
                   clicked=true;
              else
              if(clicked==true)
                   mouseloc(x,y,e.getX(),e.getY());
                   information.sortShapes();
                   temp.repaint();
                   clicked=false;
         public void mouseloc(int xt,int yt,int xl,int yl)
              loc[0]=xt;
              loc[1]=yt;
              loc[2]=xl;
              loc[3]=yl;
              newshape.setLoc(xt,yt,xl,yl);
              newshape.doDraw(true);
    class MyShape
         private int xL, yL, xR, yR; //Local location ints for this class;
         private int red, blue, green; //Local ints defining this color;
         private int shape,fill; //Local info about shape
         private boolean draw=false; // Determines if Shape will draw
         private boolean setupshape=true;
         public void MyShape()
         public void doDraw(boolean a)
              draw=a;
         public void setLoc(int xt,int yt,int xb,int yb)
              xL=xt;
              yL=yt;
              xR=xb;
              yR=yb;
         public void setColor(int r,int b,int g)
              red=r;
              blue=b;
              green=g;
         public void setShape(int thisshape)
              shape=thisshape;
         public void setFill(int fil)
              fill=fil;
         public void drawShape(Graphics g)
              if(draw==true && setupshape==true)
                   System.out.println("This shape setup");
                   g.setColor(new Color(red,blue,green));
                   switch(shape)
                        case 0: makeLine(g);break;
                        case 1: makeRect(g);break;
                        case 2: makeOval(g);break;
                   setupshape=false;
              else if(draw==true)
                   System.out.println("This shape redrawn");
                   switch(shape)
                        case 0: drawLine(g);break;
                        case 1: drawRect(g);break;
                        case 2: drawOval(g);break;
         public void reset(boolean a)
              setupshape=a;
         public void drawLine(Graphics g)
              g.drawLine(xL,yL,xR,yR);
         public void drawRect(Graphics g)
              if(fill==0)
                   g.drawRect(xL,yL,xR,yR);
              else
                   g.fillRect(xL,yL,xR,yR);
         public void drawOval(Graphics g)
              if(fill==0)
                   g.drawOval(xL,yL,xR,yR);
              else
                   g.fillOval(xL,yL,xR,yR);
         public void makeLine(Graphics g)
              g.drawLine(xL,yL,xR,yR);
         public void makeRect(Graphics g)
              sortvalue();
              if(fill==0)
                   g.drawRect(xL,yL,xR,yR);
              else
                   g.fillRect(xL,yL,xR,yR);
         public void makeOval(Graphics g)
              sortvalue();
              if(fill==0)
                   g.drawOval(xL,yL,xR,yR);
              else
                   g.fillOval(xL,yL,xR,yR);
         public void sortvalue()
                   if(xR<xL)
                   int temp=xR;
                   xR=xL;
                   xL=temp;
              if(yR<yL)
                   int temp=yR;
                   yR=yL;
                   yL=temp;
              yR=(yR-yL);
              xR=(xR-xL);     

    Sorry mate but you need a lot of work....
    I like what you've done but (in my humble opinion) it needs a lot of reworking.
    Your problem is you're not storing the shapes. You've set up an array but you never assign the shapes to it. I would reccomend using a vector. Heres a quick bit of pseudo code.
    Listener class
    mouseClicked method
    if first click
    get mouse x/y
    if second click
    get mouse x/y
    create new MyShape(x1, y1, x2, y2)
    call data.addShape(new MyShape)
    Data class
    constructor
    this.myVector = new Vector()
    addShape(MyShape shape) method
    this.myVector.addElement(shape) -- add new shape
    this.myVector.remove(0) -- remove bottom shape
    drawAllShapes method
    Enumeration enum= this.myVector.elements()
    while(enum.hasMoreElements())
    MyShape shape = (MyShape)enum.nextElement()
    shape.draw()
    Feel free to ask any questions.
    Rob.

Maybe you are looking for

  • Flash won't install on Mac v. 10.9.5

    The issue is the same as the discussion about Mac v 10.10. Here are the last view log files: 2014-08-20 09:03:28 -0400 [I]  IM: ---------- log start ---------- 2014-08-20 09:03:28 -0400 [I]  IM: 1407 2014-08-20 09:03:29 -0400 [I]  IM: 1407 2014-08-20

  • Unable to install trial version of Acrobat Pro XI

    I am unable to install a trial version of Acrobat Pro XI from the link on the site: Download Adobe Acrobat free trial | Acrobat XI Professional It keeps saying that the installer file is damaged. Can someone please help? Thanks.

  • Some questions related to site studio 10gR4

    Hi everyone We are developing a solution using UCM, and I have couple of questions regarding the usage of the site studio 10gR4. It will be really great if any one of you can either answer or point me to the rite document/webpage where I can get thes

  • Settings, preferences for the Sequence

    i'm capturing footage i shot with the panasonic 100a, and before i bring footage into a project to edit i need to make sure my original presets are what i need from here on out.... i just want the most 'pure' treatment of my footage once it's in the

  • 2007 Upgrade Error Company DB not consistent

    Hi there, I am currently using SAP b1 2005 server and client im using Sql server 2005 for for database while upgrading the system from 2005 to 2007 every thing(b1 server, client,company database) upgraded succesfully but while loging into company it