0

背景情報:

以下で構成されるビジュアルダイアグラムエディターを実装しています

  • さまざまな複雑な要素 (サイズ変更可能、タイトル バー、サブ要素付き) および
  • さまざまな単純な要素 (サイズ変更不可、タイトル バーなし、サブ要素なし)。

すべての要素はドラッグ可能です。

概略図の要素を表すために、JInternalFrame (複雑な要素の場合) と JPanel (単純な要素の場合) を使用しています。これらすべての要素を含むコンテナー (JDesktopPane または JLayeredPane) があります。

この概念にはいくつかの問題があります。

ケース 1 - コンテナーが JDesktopPane の場合:

  • JInternalFrames は、常に他の要素の上にあります。
  • 他の要素をクリックしても、以前にアクティブだった JInternalFrame が「非アクティブ化」されない

ケース 2 - コンテナーは JLayeredPane です。

  • JInternalFrame 内のいくつかの要素をクリックすると、永久に「アクティブ化」されたままになります。

ケース 3 - JInternalFrame はすべてに使用されますが、単純な要素の装飾はありません。

  • カスタム枠(JInternalFrame のタイトル バーを手動で削除するときに必要)は、JInternalFrame をアクティブ化/非アクティブ化した後、常に現在の LAF 枠に置き換えられます。

とにかく、JInternalFrames をアクティブ化する背後にある概念全体がわかりません。 JInternalFrame をまったくアクティブにできないようにすることができれば、ケース 2を選択できます。

与えられた問題に対する単純で直接的な解決策は何か、私にアドバイスしてください。

注: コンポーネントの選択と JInternalFrame のアクティブ化は別のもののようです。

4

2 に答える 2

0

JInternalFrame =を初期化するときに、これを試してください。

 new JInternalFrame(<your args>) {
          protected void fireInternalFrameEvent(int id){  
               if (id != InternalFrameEvent.INTERNAL_FRAME_ACTIVATED) {
                   super.fireInternalFrameEvent(id);
               }
          }
 };

のコードを見るとJInternalFrame.setSelected(boolean)、setSelectedと'actvation'はプロセスで結び付けられており、setSelectedはSelectionのプロパティ変更だけでなく、呼び出しも実行する ことに注意してくださいfireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED)

于 2009-06-26T13:19:03.220 に答える
0

私はあなたの問題を誤解しているかもしれません。JIF の setSelected() メソッドを見てみましたか? メソッドのオーバーライドと拒否可能なアクティブ化イベントがサポートされているようです。

編集: javadoc が述べているように、用語の誤解があるかもしれません:

/**
 * Selects or deselects the internal frame
 * if it's showing.
 * A <code>JInternalFrame</code> normally draws its title bar
 * differently if it is
 * the selected frame, which indicates to the user that this
 * internal frame has the focus.
 * When this method changes the state of the internal frame
 * from deselected to selected, it fires an
 * <code>InternalFrameEvent.INTERNAL_FRAME_ACTIVATED</code> event.
 * If the change is from selected to deselected,
 * an <code>InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED</code> event
 * is fired.
 *
 * @param selected  a boolean, where <code>true</code> means this internal frame
 *                  should become selected (currently active)
 *                  and <code>false</code> means it should become deselected
 * @exception PropertyVetoException when the attempt to set the
 *            property is vetoed by the <code>JInternalFrame</code>
 *
 * @see #isShowing
 * @see InternalFrameEvent#INTERNAL_FRAME_ACTIVATED
 * @see InternalFrameEvent#INTERNAL_FRAME_DEACTIVATED
 *
 * @beaninfo
 *     constrained: true
 *           bound: true
 *     description: Indicates whether this internal frame is currently
 *                  the active frame.
 */

編集 2: 2 番目のケースを読み直しました。各 JIF には、独自の個別のフォーカス/選択環境があると言えます。すべての JIF をトラバースし、選択したいコンポーネントでない限り、その中のすべてを選択解除するメソッドを作成できます。

于 2009-06-26T13:01:55.640 に答える