どのコンポーネントがJDesktopPaneの中に追加することができますか?

StackOverflow https://stackoverflow.com/questions/1474428

  •  16-09-2019
  •  | 
  •  

質問

私は、SwingでMDIアプリケーションを設計するいくつかの問題を抱えている。

私は何の問題JDesktopPaneの&のJInternalFrameの実装を持っていない、私の質問はもう少し具体的になります。ここでは一目で私のベースコンテナフレームは次のとおりです。

package applicationGUI;

import javax.swing.JFrame;

public class DesktopContainer extends JFrame{
/* Fields */

/* Constructors */
    public DesktopContainer(){
        setContentPane(new Desktop());
        setJMenuBar(AppllicationMenuBar.getMenuBar());

    }
/* Public Methods */
    public Desktop getDesktop(){
        return (Desktop)getContentPane();
    }
}

そして、私のデスクトップます:

public class Desktop extends JDesktopPane{}

私はDesktopContainerのコンテンツペインとしてデスクトップを設定して注意してください。私が欲しいのは(ちょうどJMenuBarの下に、specificially)デスクトップ上のJPanelを追加できるように、です。残念ながら、私はこれを行うことができませんでした。そして最後に、ここに私の質問があります:

1-)JPanelのオブジェクトは、JDesktopPaneの上に描画することができますか?私はいくつかの掘削をした、私はそれがのJLayeredPane能力とは何かを持っていると思いますが、残念ながら、私はそれを実装することができませんでした。

JPanelのオブジェクトがJDesktopPaneの上に描画することができない場合は、

2-)、どのように私は、私がやりたい何かアドバイスを管理することができますか?私はちょうど「JFrameのへの2つのJPanelを追加するには、ニーズに合わせて上部のいずれかを使用すると、以下の第二のJPanelにJDesktopPaneのを描く」、考え出しました。これは良いアプローチですか?

あなたの答えをありがとう..

役に立ちましたか?

解決

AのJPanelを描画することができ、JDesktopPaneの

のイベントを受信することができます。
public class DesktopContainer extends JFrame { 
/* Constructors */
    public DesktopContainer(){
        setContentPane(new Desktop());
        setJMenuBar(createJMenuBar());

        APanel a = new APanel();
        a.setBounds(0, 0, 200, 200);
        a.setVisible(true);
        getDesktop().add(a);
    }   
    ....
}

class Desktop extends JDesktopPane {
}

class APanel extends JPanel { 
    public APanel() { 
        setLayout(new BorderLayout());
        add(new JButton("Hello stackoverflow"));
    }
}

これは正常に動作します。 JInternalFrameが必要に応じて、JPanelの上でのsetVisible(true)を、setBounds()を呼び出す必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top