背景情報:
視覚的なダイアグラムエディターを実装しています。
- さまざまな複雑な要素(サイズ変更可能、タイトルバー、サブ要素付き)および
- さまざまな単純な要素(サイズ変更不可、タイトルバーなし、サブ要素なし)。
すべての要素はドラッグ可能です。
JInternalFrameを使用しています(複雑な要素用)JPanelとともに (単純な要素の場合)スケマティックダイアグラムの要素を表します。コンテナ(JDesktopPaneまたはJLayeredPaneのいずれか)があります。 これらすべての要素。
この概念にはいくつかの問題があります。
ケース1 -コンテナはJDesktopPaneです:
- JInternalFramesは常に他の要素の上にあります。
- 他の要素をクリックしても、以前アクティブだったJInternalFrameが「無効化」されない
ケース2 -コンテナはJLayeredPaneです:
- JInternalFrame内のいくつかの要素をクリックした後、 永久に「アクティブ化」されます。
ケース3 -すべてにJInternalFrameが使用されますが、単純な要素の装飾はありません。
- 私のカスタムボーダー (手動で削除するときに必要です JInternalFrameのタイトルバー) 毎回、現在のLAFボーダーに置き換えられます。 JInternalFrameのアクティブ化/非アクティブ化。
とにかくJInternalFramesをアクティブにする背後にある概念全体を理解していません。 JInternalFrameをまったくアクティブにできない場合、 私はできた 選ぶ ケース2 誰でも幸せでしょう。
与えられた問題に対するシンプルで簡単な解決策は何か、私にアドバイスしてください。
注:コンポーネントの選択とJInternalFrameのアクティブ化 異なるもののようです。
回答:
回答№1は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をトラバースし、選択したいコンポーネントを除き、その中のすべてを選択解除するメソッドを作成できます。
回答№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)
同じように。