🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7714

Re: JDialog and CardLayout problem switching between panels

#7714
From: Ed
Date: Thu, 04 Jan 2001 19:14
468 lines
18489 bytes
Thanks for the info but I am passed that.  I did not show that part but I
have successfully implemented that part (I think).

Here is what I did:


   void jbInit() throws Exception
   {
      this.getContentPane().setLayout(null);
      this.setResizable(false);
      this.setTitle("Query Wizard");
      jQueryWizardPanel.setBackground(SystemColor.control);
      jQueryWizardPanel.setEnabled(false);
      jQueryWizardPanel.setToolTipText("");
      jQueryWizardPanel.setBounds(new Rectangle(12, 10, 572, 326));
      jQueryWizardPanel.setLayout(null);
      jColumnSelectionPanel.setLayout(null);

jTelynxMetaDataTree.setBorder(BorderFactory.createLoweredBevelBorder());
      jTelynxMetaDataTree.setBounds(new Rectangle(15, 49, 234, 185));

jSelectedColumnsList.setBorder(BorderFactory.createLoweredBevelBorder());
      jSelectedColumnsList.setBounds(new Rectangle(319, 49, 234, 185));

jDeleteColumnButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jDeleteColumnButton.setText("<");
      jDeleteColumnButton.setBounds(new Rectangle(276, 77, 19, 21));
      jAddColumnButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jAddColumnButton.setText(">");
      jAddColumnButton.setBounds(new Rectangle(276, 49, 19, 21));
      jLabel3.setFont(new java.awt.Font("Dialog", 0, 11));
      jLabel3.setText(" Columns In Query");
      jLabel3.setBounds(new Rectangle(319, 29, 88, 16));
      jLabel2.setFont(new java.awt.Font("Dialog", 0, 11));
      jLabel2.setText(" Available Tables and Columns");
      jLabel2.setBounds(new Rectangle(15, 29, 147, 16));

jDeleteAllColumnsButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jDeleteAllColumnsButton.setText("<<");
      jDeleteAllColumnsButton.setBounds(new Rectangle(276, 105, 19, 21));
      jLabel1.setFont(new java.awt.Font("Dialog", 0, 11));
      jLabel1.setText(" What columns do you want to include in your
query?");
      jLabel1.setBounds(new Rectangle(10, 5, 257, 16));
      jFilterDataPanel.setLayout(null);
      jFilterDataPanel.setBackground(SystemColor.control);
      jFilterDataPanel.setBorder(BorderFactory.createEtchedBorder());
      jColumnSelectionPanel.setBackground(SystemColor.control);
      jColumnSelectionPanel.setBorder(BorderFactory.createEtchedBorder());
      jOverlappingPanels.setBackground(Color.yellow);
      jOverlappingPanels.setBounds(new Rectangle(-1, 2, 571, 264));
      jOverlappingPanels.setLayout(cardLayout);

jSelectedColumnsList1.setBorder(BorderFactory.createLoweredBevelBorder());
      jSelectedColumnsList1.setBounds(new Rectangle(12, 82, 206, 174));
      jCancelButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jCancelButton.setText("Cancel");
      jCancelButton.setBounds(new Rectangle(472, 277, 101, 27));
      jCancelButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            jCancelButton_actionPerformed(e);
         }
      });
      jNextButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jNextButton.setText("Next >");
      jNextButton.setBounds(new Rectangle(355, 277, 101, 27));
      jNextButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            jNextButton_actionPerformed(e);
         }
      });
      jBackButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jBackButton.setText("< Back");
      jBackButton.setBounds(new Rectangle(238, 277, 101, 27));
      jBackButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            jBackButton_actionPerformed(e);
         }
      });
      jHelpButton.setBorder(BorderFactory.createRaisedBevelBorder());
      jHelpButton.setMaximumSize(new Dimension(31, 27));
      jHelpButton.setMinimumSize(new Dimension(31, 27));
      jHelpButton.setPreferredSize(new Dimension(31, 27));
      jHelpButton.setText("Help");
      jHelpButton.setBounds(new Rectangle(-1, 277, 101, 27));
      jHelpButton.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(ActionEvent e)
            { jHelpButton_actionPerformed(e); }
      }  );
      jSortOrderPanel.setLayout(null);
      jSortOrderPanel.setBackground(SystemColor.control);
      jSortOrderPanel.setBorder(BorderFactory.createEtchedBorder());
      jLabel4.setText(" Column to Filter:");
      jLabel4.setBounds(new Rectangle(13, 63, 106, 17));
      jLabel5.setText(" Filter the data to specify which rows to include in
your query.");
      jLabel5.setBounds(new Rectangle(13, 11, 512, 17));
      jLabel6.setText(" If you do not want to filter the data, click
Next.");
      jLabel6.setBounds(new Rectangle(13, 35, 319, 17));
      jFilterComboPanel.setBorder(BorderFactory.createEtchedBorder());
      jFilterComboPanel.setBounds(new Rectangle(234, 82, 325, 174));
      jFilterComboPanel.setLayout(null);
      jLabel7.setText(" Only include rows where:");
      jLabel7.setBounds(new Rectangle(248, 63, 180, 17));
      jOperator1ComboBox.setBounds(new Rectangle(6, 18, 151, 21));
      jOperand1ComboBox.setBounds(new Rectangle(166, 18, 151, 21));
      jOperand2ComboBox.setBounds(new Rectangle(166, 78, 151, 21));
      jOperator2ComboBox.setBounds(new Rectangle(6, 78, 151, 21));
      jOperand3ComboBox.setBounds(new Rectangle(166, 138, 151, 21));
      jOperator3ComboBox.setBounds(new Rectangle(6, 138, 151, 21));
      jAnd1RadioButton.setText("AND");
      jAnd1RadioButton.setBounds(new Rectangle(103, 43, 54, 25));
      jAnd2RadioButton.setBounds(new Rectangle(103, 102, 48, 25));
      jAnd2RadioButton.setText("AND");
      jOr1RadioButton.setBounds(new Rectangle(166, 43, 50, 25));
      jOr1RadioButton.setText("OR");
      jOr2RadioButton.setText("OR");
      jOr2RadioButton.setBounds(new Rectangle(166, 102, 50, 25));
      jLabel8.setText("Specify how you want your data sorted.  If you don\'t
want to sort " +
                                   "the data.  Click Next.");
      jLabel8.setBounds(new Rectangle(10, 13, 474, 17));
      jLabel9.setText(" Sort By:");
      jLabel9.setBounds(new Rectangle(24, 51, 51, 17));
      jComboBox7.setBounds(new Rectangle(20, 78, 161, 21));
      jRadioButton5.setText("Ascending");
      jRadioButton5.setBounds(new Rectangle(202, 70, 103, 25));
      jRadioButton6.setBounds(new Rectangle(200, 93, 103, 25));
      jRadioButton6.setText("Descending");
      jRadioButton7.setText("Descending");
      jRadioButton7.setBounds(new Rectangle(202, 151, 103, 25));
      jRadioButton8.setBounds(new Rectangle(203, 131, 103, 25));
      jRadioButton8.setText("Ascending");
      jLabel10.setBounds(new Rectangle(27, 120, 51, 17));
      jLabel10.setText("Then By:");
      jComboBox8.setBounds(new Rectangle(21, 145, 161, 21));
      jRadioButton9.setText("Descending");
      jRadioButton9.setBounds(new Rectangle(207, 226, 103, 25));
      jRadioButton10.setBounds(new Rectangle(209, 207, 103, 25));
      jRadioButton10.setText("Ascending");
      jLabel11.setBounds(new Rectangle(27, 188, 51, 17));
      jLabel11.setText("Then By:");
      jComboBox9.setBounds(new Rectangle(21, 209, 161, 21));
      jFinishPanel.setBorder(BorderFactory.createEtchedBorder());
      jFinishPanel.setLayout(null);
      jLabel12.setText(" What would you like to do Next?");
      jLabel12.setBounds(new Rectangle(17, 13, 243, 17));
      jRunReportRadioButton.setText("Run Report");
      jRunReportRadioButton.setBounds(new Rectangle(49, 48, 110, 25));
      jRunReportRadioButton.addActionListener(new
java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            jRunReportRadioButton_actionPerformed(e);
         }
      });
      jButton1.setText("Save Query");
      jButton1.setBounds(new Rectangle(426, 78, 101, 27));

      this.getContentPane().add(jQueryWizardPanel, null);
      jQueryWizardPanel.add(jOverlappingPanels, null);

      jOverlappingPanels.add(jColumnSelectionPanel, "Query Wizard -
Table/Column Selector");
      jColumnSelectionPanel.add(jLabel1, null);
      jColumnSelectionPanel.add(jTelynxMetaDataTree, null);
      jColumnSelectionPanel.add(jSelectedColumnsList, null);
      jColumnSelectionPanel.add(jLabel3, null);
      jColumnSelectionPanel.add(jLabel2, null);
      jColumnSelectionPanel.add(jAddColumnButton, null);
      jColumnSelectionPanel.add(jDeleteColumnButton, null);
      jColumnSelectionPanel.add(jDeleteAllColumnsButton, null);

      jOverlappingPanels.add(jSortOrderPanel, "Query Wizard - Sort Order");
      jSortOrderPanel.add(jLabel8, null);
      jSortOrderPanel.add(jLabel9, null);
      jSortOrderPanel.add(jComboBox7, null);
      jSortOrderPanel.add(jRadioButton10, null);
      jSortOrderPanel.add(jLabel10, null);
      jSortOrderPanel.add(jComboBox8, null);
      jSortOrderPanel.add(jLabel11, null);
      jSortOrderPanel.add(jComboBox9, null);
      jSortOrderPanel.add(jRadioButton8, null);
      jSortOrderPanel.add(jRadioButton7, null);
      jSortOrderPanel.add(jRadioButton9, null);
      jSortOrderPanel.add(jRadioButton5, null);
      jSortOrderPanel.add(jRadioButton6, null);


      jOverlappingPanels.add(jFilterDataPanel, "Query Wizard - Applied
Filter");
      jFilterDataPanel.add(jSelectedColumnsList1, null);
      jFilterDataPanel.add(jLabel6, null);
      jFilterDataPanel.add(jLabel5, null);
      jFilterDataPanel.add(jLabel4, null);
      jFilterDataPanel.add(jFilterComboPanel, null);

      jOverlappingPanels.add(jFinishPanel, "Query Wizard - Finish");
      jFinishPanel.add(jLabel12, null);
      jFinishPanel.add(jRunReportRadioButton, null);
      jFinishPanel.add(jButton1, null);

      jFilterComboPanel.add(jOperand1ComboBox, null);
      jFilterComboPanel.add(jOperator1ComboBox, null);
      jFilterComboPanel.add(jOperator3ComboBox, null);
      jFilterComboPanel.add(jOperand3ComboBox, null);
      jFilterComboPanel.add(jOperator2ComboBox, null);
      jFilterComboPanel.add(jOperand2ComboBox, null);
      jFilterComboPanel.add(jAnd2RadioButton, null);
      jFilterComboPanel.add(jOr2RadioButton, null);
      jFilterComboPanel.add(jAnd1RadioButton, null);
      jFilterComboPanel.add(jOr1RadioButton, null);
      jFilterDataPanel.add(jLabel7, null);
      jQueryWizardPanel.add(jCancelButton, null);
      jQueryWizardPanel.add(jBackButton, null);
      jQueryWizardPanel.add(jNextButton, null);
      jQueryWizardPanel.add(jHelpButton, null);

      this.setBounds(200,210,605,350);
   }

As you can see my jOverLappingPanels adds the four Panels to it correctly.

and my control outside the OverLappingPanel but in the same JDialog switches
    between the Panels as you indicated in your message correctly as below:

               CardLayout cl = (CardLayout) jFilterDataPanel.getLayout();
               if ( cl == null)
                  { cl = null; }
               else
                  {
                  cl.show( jFilterDataPanel, "Query Wizard - Filter" );
                  bSuccess = true;
                  }

What I get is cl is null above.  I wonder if I am creating the JDialog
correctly
at all.  The JDialog comes up and I can exit from it, I can even see the
first panel
of the four panels in the OverLappingPanel containing the four panels.  But
as
soon as I try to use the control to switch to the next panel to process the
code above
I cannot get the CardLayout pointer and the value being returned is null
from:

CardLayout cl = jColumnSelectionPanel.getLayout();

Can you provide some insight why it is invalid (actually it is null) ?????


Thanks In Advance,
Ed




Torsten Welches <torsten.welches@who.cares.netcologne.de> wrote in message
news:3a54c374_2@dnews...
> Ed,
>
> unfortunately you didn't show QueryWizardDialog's jbInit(), I assume this
is
> the method where you are a) applying the CardLayout and b) add the JPanels
> to the Container that uses the CardLayout.
>
> Basically it's like that:
> file://add a panel
> cardPanel.add(aPanel, someString); file://someString identifies the
component
> being added - use it for show(...) later!
> ...
> file://switch card
> CardLayout cl = (CardLayout)(cardPanel.getLayout());
> cl.show(cardPanel, someString);
>
> Good luck,
> Torsten
>
> Ed schrieb in Nachricht <3a54aca1$1_1@dnews>...
> >I have created a JDialog that is instantiated once my application is
> running
> >by selecting a button.  In other words it is not built on top of the
Frame
> >of the application's project.
> >
> >I passed this frame into the Dialog's constructor thinking the JDialog
> super
> >constructor needs the Frame reference in it's constructor - I am not sure
> >about that though.
> >
> >Here is what I did essentially:
> >
> >
> >public class Frame1 extends JFrame
> >{
> >JPanel contentPane;
> >XYLayout xYLayout = new XYLayout();
> >JButton jRunButton = new JButton();
> >
> >  ...
> >
> >
> > void jRunButton_actionPerformed(ActionEvent e)
> >   {
> >      String CommandString = e.getActionCommand();
> >      int nReportRequest = jReportList.getSelectedIndex();
> >      JReportManager reportManager = new JReportManager( this,
> >nReportRequest);
> >   }
> >
> >} // end of Frame1 class
> >
> >
> >
> >
> >import telynx.QueryWizard.QueryWizardDialog;
> >import javax.swing.JFrame;
> >
> >public class JReportManager
> >{
> >
> >// the report type options - passed into the JReportManager Constructor
> >private static final int CUSTOMIZE_REPORT = 8;
> >
> >
> >   public JReportManager()
> >      {}
> >
> >   public JReportManager( JFrame parentFrame, int reportRequest )
> >   {
> >      switch ( reportRequest )
> >         {
> >         case CUSTOMIZE_REPORT:
> >            try
> >               {
> >               QueryWizardDialog QueryWizard = new
> >QueryWizardDialog(parentFrame);
> >               QueryWizard.show();
> >               }
> >            catch( Exception e )
> >               { e.printStackTrace(); }
> >            break;
> >
> >         }
> >   }
> >
> >}
> >
> >
> >
> >
> >
> >
> >public class QueryWizardDialog extends JDialog
> >{
> >static final int TABLE_SELECTOR_PANEL_INDEX = 0;
> >static final int FILTER_PANEL_INDEX = TABLE_SELECTOR_PANEL_INDEX + 1;
> >static final int SORT_PANEL_INDEX = FILTER_PANEL_INDEX + 1;
> >static final int FINISH_PANEL_INDEX = SORT_PANEL_INDEX + 1;
> >static final int MAX_OVERLAPPING_PANEL = FINISH_PANEL_INDEX + 1;
> >
> >int iiPanelIndicator = 0;
> >JPanel jQueryWizardPanel = new JPanel();
> >JPanel jOverlappingPanels = new JPanel();
> >
> >CardLayout cardLayout = new CardLayout();
> >JPanel jColumnSelectionPanel = new JPanel();
> >JPanel jFilterDataPanel = new JPanel();
> >JPanel jSortOrderPanel = new JPanel();
> >JPanel jFinishPanel = new JPanel();
> >
> >
> >   public QueryWizardDialog(JFrame parentFrame)
> >   {
> >   super( (Frame) parentFrame, "QUERY WIZARD MANAGER", true );
> >      try
> >         { jbInit(); }
> >      catch (Exception e)
> >         { e.printStackTrace();
> >         }
> >   }
> >
> >
> >
> >
> >   void jShowPanel( int panelIndicator )
> >   {
> >      try
> >         {
> >         switch ( panelIndicator )
> >            {
> >            case TABLE_SELECTOR_PANEL_INDEX:
> >
>
>((CardLayout)jColumnSelectionPanel.getLayout()).show(jColumnSelectionPanel,
> "
> >Query Wizard - Table/Column Selector");
> >               break;
> >            case FILTER_PANEL_INDEX:
> >               cardLayout.show( jFilterDataPanel, "Query Wizard -
> Filter" );
> >               break;
> >            case SORT_PANEL_INDEX:
> >
> >(CardLayout)jSortOrderPanel.getLayout()).show( jSortOrderPanel, "Query
> >Wizard - Sort" );
> >               break;
> >            case FINISH_PANEL_INDEX:
> >               ((CardLayout)jFinishPanel.getLayout()).show( jFinishPanel,
> >"Query Wizard - Finish" );
> >               break;
> >            default:
> >               break;
> >            }
> >         }
> >      catch ( Exception e )
> >         {
> >         e.printStackTrace();
> >         }
> >   }
> >
> >
> >
> >When I call the two different methods of changing panels:
> >
> >
>
>((CardLayout)jColumnSelectionPanel.getLayout()).show(jColumnSelectionPanel,
> "
> >Query Wizard - Table/Column Selector");
> >    or
> >            cardLayout.show( jFilterDataPanel, "Query Wizard - Filter" );
> >
> >I get the same result.   I get an exception.  I believe it may be because
I
> >am not getting the correct layout pointer.  (C++ background - sorry).
> >Should I be passing the original frame of the panel that is creating the
> new
> >JDialog or will JDialog create it's own frame?????
> >
> >
> >Can any one provide some insight into this.
> >
> >
> >
> >I have seen the two methods
> >
> >
>
>((CardLayout)jColumnSelectionPanel.getLayout()).show(jColumnSelectionPanel,
> "
> >Query Wizard - Table/Column Selector");
> >    or
> >            cardLayout.show( jFilterDataPanel, "Query Wizard - Filter" );
> >
> >used in changing between panels in a CardLayout arrangment of overlapping
> >panels.  Can someone clarify which is the right one to use???
> >
> >Thanks In Advance,
> >Ed
> >
> >
> >
> >
>
>
Technical Details
Message-ID: <3a54cc17_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!news.algonet.se!algonet!neel.uni2.net!newssuck.uni2.dk!bornews.borland.com!dnews!12.39.173.65
References: <3a54aca1$1_1@dnews> <3a54c374_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,346c49090a946af6
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-04 11:22:57 PST
Reply-To: "Ed" <ereyes@telynx.com>
From: "Ed" <ereyes@telynx.com>
Newsgroups: borland.public.jbuilder.java.swing
References: <3a54aca1$1_1@dnews> <3a54c374_2@dnews>
Subject: Re: JDialog and CardLayout problem switching between panels
Date: Thu, 4 Jan 2001 13:14:57 -0600
Lines: 470
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MIMEOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
NNTP-Posting-Host: 12.39.173.65
Message-ID: <3a54cc17_1@dnews>
X-Trace: 4 Jan 2001 11:16:39 -0800, 12.39.173.65
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!newsfeed.online.be!news.algonet.se!algonet!neel.uni2.net!newssuck.uni2.dk!bornews.borland.com!dnews!12.39.173.65