私のアプリケーションは、患者の記録を処理します。メイン フレームでは、ユーザーは複数の内部フレームを開くことができます。各内部フレームにはタブ付きペインが含まれ、ユーザーが作成した各タブには、患者のデータを入力できるフォームと、追加されたすべての患者が表示される jtable が含まれます。
ユーザーが jtable の行 (患者) をクリックすると、フォームのフィールドに患者のデータが入力され、"Escape" を押すとフォームのフィールドがクリアされ、ユーザーは別の患者を検索/チェック/入力することができます。
私の問題は、このエスケープ キー イベントが、使用しているSubstance ルック アンド フィールで classCastException をスローすることです。実行されたアクション用に作成したコードは正常に機能します。この問題は、タブ付きペインを使用し始めてから発生しました (すべてが単一のペインで作成される前)。ルック アンド フィールを egWindows に変更しても、例外はスローされません。何か考えはありますか?
コードのサンプルを次に示します。
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);
}
これはスローされる例外です:
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)
そして、これは例外を引き起こすコードです:
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;
}