簡體   English   中英

Swing:如何使JInternalFrame與容器內的其他組件同等對待?

[英]Swing: How could I get JInternalFrame treated equally to other components inside a container?

背景資料:

我正在實現一個可視化的圖表編輯器,其中包括

  • 不同的復雜元素(可調整大小,帶有標題欄,子元素)和
  • 不同的簡單元素(不可調整大小,沒有標題欄,沒有子元素)。

所有元素都是可拖動的。

我使用JInternalFrame(用於復雜元素)和JPanel(用於簡單元素)來表示原理圖的元素。 有一個包含所有這些元素的容器(JDesktopPane或JLayeredPane)。

這個概念有幾個問題:

情況1-容器是JDesktopPane:

  • JInternalFrames始終位於其他元素之上。
  • 單擊其他元素不會“停用”先前處於活動狀態的JInternalFrame

情況2-容器是一個JLayeredPane:

  • 單擊JInternalFrame中的某些元素后,它將永遠保持“激活”狀態。

情況3 -JInternalFrame用於所有內容,但不修飾簡單元素:

  • 在激活/停用JInternalFrame之后,每次都會用當前的LAF邊框替換我的自定義邊框(當我手動刪除JInternalFrame的標題欄時需要此邊框

無論如何,我不了解激活JInternalFrames背后的全部概念。 如果我可以使JInternalFrame根本無法激活 ,則可以選擇情況2,這將是一件令人高興的事。

請給我建議,對於給定的問題,這將是一種簡單直接的解決方案。

注意:組件的選擇和JInternalFrame的激活似乎是不同的。

我可能會誤解你的問題。 您是否嘗試過查看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:現在,我重新閱讀您的第二種情況。 我想說每個JIF都有自己單獨的焦點/選擇環境。 您可以創建一個遍歷所有JIF並取消選擇其中任何內容的方法,除非它是您想要選擇的組件。

初始化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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM