Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Click button to open JDialog

  1. #1
    Junior Member susieferrari's Avatar
    Join Date
    Mar 2011
    Location
    Parma Italy
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Click button to open JDialog

    Hi all,

    in my GUI I have a button (jButtonImportData), I would like to open a JDialog by clicking this button.

    I've added jDialog1[JDialog] so I have this item in NetBeans Inspector window.

    I have also

    private void jButtonImportDataActionPerformed(java.awt.event.ActionEvent evt) {
          // TODO add your handling code here:
        }

    but I do not know how to open the jDialog: should I have to add ActionListener()?


    Thanks

    Susie


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Click button to open JDialog

    An ActionListener sounds like the way to go. Seems like an ActionListener is going to call your jButtonImportDataActionPerformed() method. If you already have a JDialog, you should just be able to call it's setVisible(true) funciton.

    But then again, without seeing an SSCCE, I'm just guessing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member susieferrari's Avatar
    Join Date
    Mar 2011
    Location
    Parma Italy
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Click button to open JDialog

    Thanks Kevin,

    I have no code written but what NetBeans sets for swing items

    This is my main

    package analysisTool;
     
    import java.awt.event.ActionListener;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.UIManager;
     
    public class PowerGui extends javax.swing.JFrame {
     
        public PowerGui() {
            initComponents();
            jSplitPane1.setOneTouchExpandable(true);
        }
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            buttonGroupPlot = new javax.swing.ButtonGroup();
            jDialog1 = new javax.swing.JDialog();
            jPanelDataSettings = new javax.swing.JPanel();
            jPanelPreview = new javax.swing.JPanel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jPanelWarnings = new javax.swing.JPanel();
            jScrollPane2 = new javax.swing.JScrollPane();
            jTextArea2 = new javax.swing.JTextArea();
            jButtonReadFile = new javax.swing.JButton();
            jPanelSetColumns = new javax.swing.JPanel();
            jComboBoxColumn1 = new javax.swing.JComboBox();
            jComboBoxColumn2 = new javax.swing.JComboBox();
            jComboBoxColumn3 = new javax.swing.JComboBox();
            jComboBoxColumn4 = new javax.swing.JComboBox();
            jComboBoxColumn5 = new javax.swing.JComboBox();
            jComboBoxColumn6 = new javax.swing.JComboBox();
            jComboBoxColumn7 = new javax.swing.JComboBox();
            jComboBoxColumn8 = new javax.swing.JComboBox();
            jPanelColumnsDelimiter = new javax.swing.JPanel();
            jRadioButtonComma = new javax.swing.JRadioButton();
            jRadioButtonSemiColon = new javax.swing.JRadioButton();
            jRadioButtonTab = new javax.swing.JRadioButton();
            jRadioButtonSpace = new javax.swing.JRadioButton();
            jPanelDateFormat = new javax.swing.JPanel();
            jComboBoxDate = new javax.swing.JComboBox();
            jLabelDate = new javax.swing.JLabel();
            jLabelIgnoreSlashes = new javax.swing.JLabel();
            jCheckBoxDataInterpolation = new javax.swing.JCheckBox();
            jCheckBoxSetAsDefault = new javax.swing.JCheckBox();
            jButtonImportFile = new javax.swing.JButton();
            buttonGroupColumnsDelimiter = new javax.swing.ButtonGroup();
            jSplitPane1 = new javax.swing.JSplitPane();
            jDataManager = new javax.swing.JPanel();
            jPanelDataManager = new javax.swing.JPanel();
            jPanelDataInput = new javax.swing.JPanel();
            jButtonImportData = new javax.swing.JButton();
            jPanelSetData = new javax.swing.JPanel();
            jLabelTotalRows = new javax.swing.JLabel();
            jLabelStartRow = new javax.swing.JLabel();
            jLabelEndRow = new javax.swing.JLabel();
            jLabelRowsBack = new javax.swing.JLabel();
            jTextFieldTotalRows = new javax.swing.JTextField();
            jTextFieldStartRow = new javax.swing.JTextField();
            jTextFieldEndRow = new javax.swing.JTextField();
            jTextFieldRowsBack = new javax.swing.JTextField();
            jPanelPlotData = new javax.swing.JPanel();
            jRadioButtonLine = new javax.swing.JRadioButton();
            jRadioButtonBars = new javax.swing.JRadioButton();
            jRadioButtonCandlestick = new javax.swing.JRadioButton();
            jRadioButtonHeikin = new javax.swing.JRadioButton();
            jComboBoxPlot = new javax.swing.JComboBox();
            jButtonPlotData = new javax.swing.JButton();
            jSeparator1 = new javax.swing.JSeparator();
            jGraphPlot = new javax.swing.JPanel();
            jToolBar1 = new javax.swing.JToolBar();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenuFile = new javax.swing.JMenu();
            jMenuEdit = new javax.swing.JMenu();
     
            jPanelDataSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Settings", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
     
            jPanelPreview.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Preview"));
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
     
            javax.swing.GroupLayout jPanelPreviewLayout = new javax.swing.GroupLayout(jPanelPreview);
            jPanelPreview.setLayout(jPanelPreviewLayout);
            jPanelPreviewLayout.setHorizontalGroup(
                jPanelPreviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
            );
            jPanelPreviewLayout.setVerticalGroup(
                jPanelPreviewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
            );
     
            jPanelWarnings.setBorder(javax.swing.BorderFactory.createTitledBorder("Warnings"));
     
            jTextArea2.setColumns(20);
            jTextArea2.setRows(5);
            jScrollPane2.setViewportView(jTextArea2);
     
            javax.swing.GroupLayout jPanelWarningsLayout = new javax.swing.GroupLayout(jPanelWarnings);
            jPanelWarnings.setLayout(jPanelWarningsLayout);
            jPanelWarningsLayout.setHorizontalGroup(
                jPanelWarningsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
            );
            jPanelWarningsLayout.setVerticalGroup(
                jPanelWarningsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
            );
     
            jButtonReadFile.setText("Read File");
     
            jPanelSetColumns.setBorder(javax.swing.BorderFactory.createTitledBorder("Set Columns "));
     
            jComboBoxColumn1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Date", "Time", "Open", "High", "Low", "Close", "Volume", "Open Interest" }));
     
            jComboBoxColumn2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Time", "Open", "High", "Low", "Close", "Volume", "Open Interest", "Skip", " " }));
     
            jComboBoxColumn3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Open", "High", "Low", "Close", "Volume", "Open Interest", "Skip", " " }));
     
            jComboBoxColumn4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "High", "Low", "Close", "Volume", "Open Interest", "Skip" }));
     
            jComboBoxColumn5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Low", "Close", "Volume", "Open Interest", "Skip" }));
     
            jComboBoxColumn6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Close", "Volume", "Open Interest", "Skip" }));
     
            jComboBoxColumn7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Volume", "Open Interest", "Skip" }));
     
            jComboBoxColumn8.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Open Interest", "Skip" }));
     
            javax.swing.GroupLayout jPanelSetColumnsLayout = new javax.swing.GroupLayout(jPanelSetColumns);
            jPanelSetColumns.setLayout(jPanelSetColumnsLayout);
            jPanelSetColumnsLayout.setHorizontalGroup(
                jPanelSetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSetColumnsLayout.createSequentialGroup()
                    .addComponent(jComboBoxColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn6, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn7, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jComboBoxColumn8, 0, 72, Short.MAX_VALUE)
                    .addContainerGap())
            );
            jPanelSetColumnsLayout.setVerticalGroup(
                jPanelSetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSetColumnsLayout.createSequentialGroup()
                    .addGroup(jPanelSetColumnsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBoxColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jComboBoxColumn8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jPanelColumnsDelimiter.setBorder(javax.swing.BorderFactory.createTitledBorder("Columns Delimiter"));
     
            buttonGroupColumnsDelimiter.add(jRadioButtonComma);
            jRadioButtonComma.setSelected(true);
            jRadioButtonComma.setText("Comma");
     
            buttonGroupColumnsDelimiter.add(jRadioButtonSemiColon);
            jRadioButtonSemiColon.setText("Semi-Colon");
     
            buttonGroupColumnsDelimiter.add(jRadioButtonTab);
            jRadioButtonTab.setText("Tab");
     
            buttonGroupColumnsDelimiter.add(jRadioButtonSpace);
            jRadioButtonSpace.setText("Space");
     
            javax.swing.GroupLayout jPanelColumnsDelimiterLayout = new javax.swing.GroupLayout(jPanelColumnsDelimiter);
            jPanelColumnsDelimiter.setLayout(jPanelColumnsDelimiterLayout);
            jPanelColumnsDelimiterLayout.setHorizontalGroup(
                jPanelColumnsDelimiterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelColumnsDelimiterLayout.createSequentialGroup()
                    .addComponent(jRadioButtonComma)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jRadioButtonSemiColon)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jRadioButtonTab)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jRadioButtonSpace)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            jPanelColumnsDelimiterLayout.setVerticalGroup(
                jPanelColumnsDelimiterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelColumnsDelimiterLayout.createSequentialGroup()
                    .addGroup(jPanelColumnsDelimiterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButtonComma)
                        .addComponent(jRadioButtonSemiColon)
                        .addComponent(jRadioButtonTab)
                        .addComponent(jRadioButtonSpace))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jPanelDateFormat.setBorder(javax.swing.BorderFactory.createTitledBorder("Date Format"));
     
            jComboBoxDate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "yyyyMMdd", "ddMMyyyy", "MMddyyyy", "MMyyyy", "yyyyMM" }));
     
            jLabelDate.setText("Date");
     
            jLabelIgnoreSlashes.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
            jLabelIgnoreSlashes.setText("Ignore Slashes");
     
            javax.swing.GroupLayout jPanelDateFormatLayout = new javax.swing.GroupLayout(jPanelDateFormat);
            jPanelDateFormat.setLayout(jPanelDateFormatLayout);
            jPanelDateFormatLayout.setHorizontalGroup(
                jPanelDateFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDateFormatLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabelDate)
                    .addGap(18, 18, 18)
                    .addComponent(jComboBoxDate, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(jLabelIgnoreSlashes)
                    .addContainerGap(24, Short.MAX_VALUE))
            );
            jPanelDateFormatLayout.setVerticalGroup(
                jPanelDateFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDateFormatLayout.createSequentialGroup()
                    .addGroup(jPanelDateFormatLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelDate)
                        .addComponent(jComboBoxDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelIgnoreSlashes))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jCheckBoxDataInterpolation.setText("Data Interpolation");
     
            jCheckBoxSetAsDefault.setText("Set as Default");
     
            jButtonImportFile.setText("Import File");
     
            javax.swing.GroupLayout jPanelDataSettingsLayout = new javax.swing.GroupLayout(jPanelDataSettings);
            jPanelDataSettings.setLayout(jPanelDataSettingsLayout);
            jPanelDataSettingsLayout.setHorizontalGroup(
                jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                    .addGroup(jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                            .addComponent(jPanelColumnsDelimiter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jPanelDateFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
                            .addGroup(jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jButtonImportFile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jCheckBoxSetAsDefault, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDataSettingsLayout.createSequentialGroup()
                            .addComponent(jPanelPreview, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(jCheckBoxDataInterpolation, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jPanelWarnings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jButtonReadFile, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jPanelSetColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
            jPanelDataSettingsLayout.setVerticalGroup(
                jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                    .addComponent(jButtonReadFile, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanelWarnings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jCheckBoxDataInterpolation)
                    .addGap(8, 8, 8)
                    .addComponent(jPanelSetColumns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanelDataSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanelColumnsDelimiter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelDataSettingsLayout.createSequentialGroup()
                            .addComponent(jCheckBoxSetAsDefault)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jButtonImportFile, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jPanelDateFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
     
            javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
            jDialog1.getContentPane().setLayout(jDialog1Layout);
            jDialog1Layout.setHorizontalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanelDataSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 717, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            jDialog1Layout.setVerticalGroup(
                jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDialog1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanelDataSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(24, Short.MAX_VALUE))
            );
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            jSplitPane1.setDividerLocation(230);
            jSplitPane1.setDividerSize(7);
     
            jPanelDataManager.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Manager", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
     
            jPanelDataInput.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Input"));
     
            jButtonImportData.setText("Import Data");
            jButtonImportData.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButtonImportDataActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout jPanelDataInputLayout = new javax.swing.GroupLayout(jPanelDataInput);
            jPanelDataInput.setLayout(jPanelDataInputLayout);
            jPanelDataInputLayout.setHorizontalGroup(
                jPanelDataInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataInputLayout.createSequentialGroup()
                    .addComponent(jButtonImportData)
                    .addContainerGap(88, Short.MAX_VALUE))
            );
            jPanelDataInputLayout.setVerticalGroup(
                jPanelDataInputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataInputLayout.createSequentialGroup()
                    .addComponent(jButtonImportData)
                    .addContainerGap(56, Short.MAX_VALUE))
            );
     
            jPanelSetData.setBorder(javax.swing.BorderFactory.createTitledBorder("Set Data"));
     
            jLabelTotalRows.setText("Total Rows");
     
            jLabelStartRow.setText("Start Row");
     
            jLabelEndRow.setText("End Row");
     
            jLabelRowsBack.setText("Rows Back");
     
            javax.swing.GroupLayout jPanelSetDataLayout = new javax.swing.GroupLayout(jPanelSetData);
            jPanelSetData.setLayout(jPanelSetDataLayout);
            jPanelSetDataLayout.setHorizontalGroup(
                jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSetDataLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabelTotalRows)
                        .addComponent(jLabelStartRow)
                        .addComponent(jLabelEndRow)
                        .addComponent(jLabelRowsBack))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jTextFieldRowsBack)
                        .addComponent(jTextFieldEndRow)
                        .addComponent(jTextFieldStartRow)
                        .addComponent(jTextFieldTotalRows, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
                    .addContainerGap())
            );
            jPanelSetDataLayout.setVerticalGroup(
                jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSetDataLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabelTotalRows)
                        .addComponent(jTextFieldTotalRows, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldStartRow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelStartRow))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldEndRow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelEndRow))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanelSetDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldRowsBack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelRowsBack))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jPanelPlotData.setBorder(javax.swing.BorderFactory.createTitledBorder("Plot Data"));
     
            buttonGroupPlot.add(jRadioButtonLine);
            jRadioButtonLine.setSelected(true);
            jRadioButtonLine.setText("Line On");
     
            buttonGroupPlot.add(jRadioButtonBars);
            jRadioButtonBars.setText("Bars");
     
            buttonGroupPlot.add(jRadioButtonCandlestick);
            jRadioButtonCandlestick.setText("Candlestick");
     
            buttonGroupPlot.add(jRadioButtonHeikin);
            jRadioButtonHeikin.setText("Heikin-Ashi");
     
            jComboBoxPlot.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Close", "Open", "High", "Low", "(Min+Max)/2", "(Open+Close)/2" }));
     
            jButtonPlotData.setText("Plot Data");
     
            javax.swing.GroupLayout jPanelPlotDataLayout = new javax.swing.GroupLayout(jPanelPlotData);
            jPanelPlotData.setLayout(jPanelPlotDataLayout);
            jPanelPlotDataLayout.setHorizontalGroup(
                jPanelPlotDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelPlotDataLayout.createSequentialGroup()
                    .addGroup(jPanelPlotDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelPlotDataLayout.createSequentialGroup()
                            .addComponent(jRadioButtonLine)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBoxPlot, 0, 106, Short.MAX_VALUE))
                        .addComponent(jRadioButtonBars)
                        .addGroup(jPanelPlotDataLayout.createSequentialGroup()
                            .addComponent(jRadioButtonHeikin)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                            .addComponent(jButtonPlotData))
                        .addComponent(jRadioButtonCandlestick))
                    .addContainerGap())
            );
            jPanelPlotDataLayout.setVerticalGroup(
                jPanelPlotDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelPlotDataLayout.createSequentialGroup()
                    .addContainerGap(11, Short.MAX_VALUE)
                    .addGroup(jPanelPlotDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButtonLine)
                        .addComponent(jComboBoxPlot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jRadioButtonBars)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jRadioButtonCandlestick)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanelPlotDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButtonHeikin)
                        .addComponent(jButtonPlotData)))
            );
     
            javax.swing.GroupLayout jPanelDataManagerLayout = new javax.swing.GroupLayout(jPanelDataManager);
            jPanelDataManager.setLayout(jPanelDataManagerLayout);
            jPanelDataManagerLayout.setHorizontalGroup(
                jPanelDataManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanelDataInput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelPlotData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelSetData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            jPanelDataManagerLayout.setVerticalGroup(
                jPanelDataManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataManagerLayout.createSequentialGroup()
                    .addComponent(jPanelDataInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanelSetData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanelPlotData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            );
     
            javax.swing.GroupLayout jDataManagerLayout = new javax.swing.GroupLayout(jDataManager);
            jDataManager.setLayout(jDataManagerLayout);
            jDataManagerLayout.setHorizontalGroup(
                jDataManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDataManagerLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanelDataManager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
            );
            jDataManagerLayout.setVerticalGroup(
                jDataManagerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jDataManagerLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanelDataManager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(448, Short.MAX_VALUE))
            );
     
            jSplitPane1.setLeftComponent(jDataManager);
     
            javax.swing.GroupLayout jGraphPlotLayout = new javax.swing.GroupLayout(jGraphPlot);
            jGraphPlot.setLayout(jGraphPlotLayout);
            jGraphPlotLayout.setHorizontalGroup(
                jGraphPlotLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 1249, Short.MAX_VALUE)
            );
            jGraphPlotLayout.setVerticalGroup(
                jGraphPlotLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 903, Short.MAX_VALUE)
            );
     
            jSplitPane1.setRightComponent(jGraphPlot);
     
            jToolBar1.setRollover(true);
     
            jMenuFile.setText("File");
            jMenuBar1.add(jMenuFile);
     
            jMenuEdit.setText("Edit");
            jMenuBar1.add(jMenuEdit);
     
            setJMenuBar(jMenuBar1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(23, 23, 23)
                            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1487, Short.MAX_VALUE))
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 673, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 905, Short.MAX_VALUE)
                    .addContainerGap())
            );
     
            getAccessibleContext().setAccessibleParent(this);
     
            pack();
        }// </editor-fold>
     
        private void jButtonImportDataActionPerformed(java.awt.event.ActionEvent evt) {
         jButtonImportData.addActionListener((ActionListener) jDialog1);
         jDialog1.setVisible(true);
        }
     
     
        public static void main(String args[]) {
     
            try{
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }
            catch(UnsupportedLookAndFeelException e){
                //handle exception
            }
            catch(ClassNotFoundException e){
                //handle exception
            }
            catch(InstantiationException e){
                //handle exception
            }
            catch(IllegalAccessException e){
                //handle exception
            }
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new PowerGui().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.ButtonGroup buttonGroupColumnsDelimiter;
        private javax.swing.ButtonGroup buttonGroupPlot;
        private javax.swing.JButton jButtonImportData;
        private javax.swing.JButton jButtonImportFile;
        private javax.swing.JButton jButtonPlotData;
        private javax.swing.JButton jButtonReadFile;
        private javax.swing.JCheckBox jCheckBoxDataInterpolation;
        private javax.swing.JCheckBox jCheckBoxSetAsDefault;
        private javax.swing.JComboBox jComboBoxColumn1;
        private javax.swing.JComboBox jComboBoxColumn2;
        private javax.swing.JComboBox jComboBoxColumn3;
        private javax.swing.JComboBox jComboBoxColumn4;
        private javax.swing.JComboBox jComboBoxColumn5;
        private javax.swing.JComboBox jComboBoxColumn6;
        private javax.swing.JComboBox jComboBoxColumn7;
        private javax.swing.JComboBox jComboBoxColumn8;
        private javax.swing.JComboBox jComboBoxDate;
        private javax.swing.JComboBox jComboBoxPlot;
        private javax.swing.JPanel jDataManager;
        private javax.swing.JDialog jDialog1;
        private javax.swing.JPanel jGraphPlot;
        private javax.swing.JLabel jLabelDate;
        private javax.swing.JLabel jLabelEndRow;
        private javax.swing.JLabel jLabelIgnoreSlashes;
        private javax.swing.JLabel jLabelRowsBack;
        private javax.swing.JLabel jLabelStartRow;
        private javax.swing.JLabel jLabelTotalRows;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JMenu jMenuEdit;
        private javax.swing.JMenu jMenuFile;
        private javax.swing.JPanel jPanelColumnsDelimiter;
        private javax.swing.JPanel jPanelDataInput;
        private javax.swing.JPanel jPanelDataManager;
        private javax.swing.JPanel jPanelDataSettings;
        private javax.swing.JPanel jPanelDateFormat;
        private javax.swing.JPanel jPanelPlotData;
        private javax.swing.JPanel jPanelPreview;
        private javax.swing.JPanel jPanelSetColumns;
        private javax.swing.JPanel jPanelSetData;
        private javax.swing.JPanel jPanelWarnings;
        private javax.swing.JRadioButton jRadioButtonBars;
        private javax.swing.JRadioButton jRadioButtonCandlestick;
        private javax.swing.JRadioButton jRadioButtonComma;
        private javax.swing.JRadioButton jRadioButtonHeikin;
        private javax.swing.JRadioButton jRadioButtonLine;
        private javax.swing.JRadioButton jRadioButtonSemiColon;
        private javax.swing.JRadioButton jRadioButtonSpace;
        private javax.swing.JRadioButton jRadioButtonTab;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JSeparator jSeparator1;
        private javax.swing.JSplitPane jSplitPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextArea jTextArea2;
        private javax.swing.JTextField jTextFieldEndRow;
        private javax.swing.JTextField jTextFieldRowsBack;
        private javax.swing.JTextField jTextFieldStartRow;
        private javax.swing.JTextField jTextFieldTotalRows;
        private javax.swing.JToolBar jToolBar1;
        // End of variables declaration
     
    }

    and these are picture of Navigator, jDialog and main GUI

    A00115.jpgA00116.jpgA00118.jpg

    I've just added

    private void jButtonImportDataActionPerformed(java.awt.event.ActionEvent evt) {
         jButtonImportData.addActionListener((ActionListener) jDialog1);
         jDialog1.setVisible(true);
        }

    but it doesn't work

    Regards,

    Susie

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Click button to open JDialog

    Yikes, that is waay too much code- we simply don't have time to sift through all of it, especially if it has been generated by a GUI-builder. I recommend you ditch the GUI-builder and throw together an SSCCE.

    Also, saying "it doesn't work" is about as useful as us saying "well then fix it!" What happened? Did you get an Exception? Some weird behavior? Something else?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member susieferrari's Avatar
    Join Date
    Mar 2011
    Location
    Parma Italy
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Click button to open JDialog

    You are right Kevin: to keep it simple, I have a Button on a Panel on a Frame. By clicking this button I would like to run a Dialog

    This is what I have for listener

     private void jButtonImportDataActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         jButtonImportData.addActionListener((ActionListener) jDialog1);
         jDialog1.setVisible(true);
        }

    and this is what I get as output

    run:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JDialog cannot be cast to java.awt.event.ActionListener
            at analysisTool.PowerGui.jButtonImportDataActionPerformed(PowerGui.java:544)
            at analysisTool.PowerGui.access$000(PowerGui.java:8)
            at analysisTool.PowerGui$1.actionPerformed(PowerGui.java:330)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6289)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6054)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4652)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4482)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4482)
            at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
            at java.awt.EventQueue.access$000(EventQueue.java:85)
            at java.awt.EventQueue$1.run(EventQueue.java:603)
            at java.awt.EventQueue$1.run(EventQueue.java:601)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
            at java.awt.EventQueue$2.run(EventQueue.java:617)
            at java.awt.EventQueue$2.run(EventQueue.java:615)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Regards,

    Susie

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Click button to open JDialog

    That Exception pretty much sums it up- you're trying to cast a JDialog as an ActionListener. You can't do that. You have to either use a class that extends ActionListener or an anonymous inner class.

    Recommended reading: How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member susieferrari's Avatar
    Join Date
    Mar 2011
    Location
    Parma Italy
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Click button to open JDialog

    Ok I found how to: just add

      private void jButtonImportDataActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        jDialog1.setVisible(true);
        }

    Susie

Similar Threads

  1. Waiting for a Second JButton Click
    By Firebert in forum Java Theory & Questions
    Replies: 0
    Last Post: March 16th, 2011, 08:15 PM
  2. how to open a jsp in a new jsp
    By ajincoep in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 7th, 2011, 05:45 AM
  3. How to press button to open another window
    By vkokaram in forum AWT / Java Swing
    Replies: 1
    Last Post: July 18th, 2010, 03:51 PM
  4. close JDialog on button click
    By Christophe in forum AWT / Java Swing
    Replies: 4
    Last Post: April 4th, 2010, 11:04 PM
  5. Click to start and drawString fonts
    By Campos in forum Java Applets
    Replies: 3
    Last Post: July 24th, 2009, 02:24 PM