views:

292

answers:

1

Good morning everyone!

I need your help!

My application processes patient records. In the main frame user can open several internal frames. Each internal frame contains a tabbed pane and each tab created by the user contains a form where he can enter patient's data and a jtable where all added patients are shown.

When the user clicks a row(patient) in the jtable the form's fields is filled by patient's data and when he presses "Escape" the form's fields are cleared and the user can go on to search/check/enter another patient.

My problem is that this escape key event, throws a classCastException in the Substance look and feel i use. The code I've written for the action performed works fine. This problem appeared since i started to use tabbed panes (before everything was made in a single pane). If i change look and feel to e.g.Windows no exception is thrown. Do you have any idea?

Here is a sample of code:

private void db_existKeyReleased(java.awt.event.KeyEvent evt) {
    // TODO add your handling code here:

    if(evt.getKeyCode()==KeyEvent.VK_ESCAPE)
    {
        searchField.requestFocusInWindow();         // if user doesn't want to process any of the entries shown to the table
        if(searchField.getText().length()>=1)       // focus goes to search field and data pane fields are cleared form previous shows
        {
            dataPane.setPid(-1); 
            dataPane.getPersonalDataPane().clearAll();
            treat_diagPane.getDiagnosis_pane().clearAll();
            treat_diagPane.getTreat_pane().clearAll(); 

        }

        DefaultTableModel model=new DefaultTableModel(
                new Object [][] {

        },
        new String [] {
            bundle.getString("lname"), bundle.getString("fname"), bundle.getString("date_birth"), bundle.getString("occupation")
        });
        db_exist.setModel(model);
    }

This is the exception thrown :

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JTabbedPane cannot be cast to javax.swing.JDesktopPane
    at javax.swing.plaf.basic.BasicDesktopPaneUI$Actions.actionPerformed(BasicDesktopPaneUI.java:329)
    at org.jvnet.lafwidget.tabbed.TabPagerWidget$4.actionPerformed(TabPagerWidget.java:158)

and this is the code that causes the exception:

public void actionPerformed(ActionEvent e) {
        JDesktopPane dp = (JDesktopPane)e.getSource();
        String key = getName();

        if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key ||
                RESTORE == key) {
            setState(dp, key);
        }
        else if (ESCAPE == key) {
            if (sourceFrame == dp.getSelectedFrame() &&
                    focusOwner != null) {
                focusOwner.requestFocus();
            }
            moving = false;
            resizing = false;
            sourceFrame = null;
            focusOwner = null;
        }

Sorry for my long message!

+2  A: 
sateesh
You are very right, but unfortunately the code that causes the exception is not mine but substance look and feel, and unfortunately i cannot change it, and if i could i don't know if that would cause other problems. Is it possible that some look and feels don't "run" properly for some applications?Should i just change the look and feel? Thank you so much for your immediate answer! Awesome work in here!
gosling
Sorry, I am not aware of 'Substance' look and feel and I had posted my answer entirely looking at the stacktrace, and assuming that you can modify code in actionPerformed method. I hope knowlegable users of Substance LF would provide a solution that would work for you.
sateesh