开发者

creating movable panel inside frame in java

开发者 https://www.devze.com 2023-03-04 09:16 出处:网络
I am trying to build simple application, just for knowledge. I would like to build something like option box. From menu when user clicks any option(like preferences) th开发者_如何学编程en a movable pa

I am trying to build simple application, just for knowledge. I would like to build something like option box. From menu when user clicks any option(like preferences) th开发者_如何学编程en a movable panel appears.

JFrame contains menu bar, and suitable menu item on clicked should cause a JPanel to appear.

I got no idea to proceed. Can anyone help me?


If you mean to open a dialog, have a look at JDialog.


If you want the moveable pane inside your JFrame, you should check JDesktopPane + InternalFrame.


Getting the point i guess you are trying to build a desktop like structure were you need to have different frame like in desktop we open two notpad files at same time n it should be movable in that can i suggesst you to use JInternalframe on a Desktoppane inside a JFrame like this:

public class Demo {
    public static void main(String[] args) {
        
        JFrame jf=new JFrame();
        jf.setLayout(null);
        jf.setSize(1280, 720);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        JDesktopPane jDesktopPane=new JDesktopPane();
        jDesktopPane.setBounds(0, 0, 1280, 720);
        jDesktopPane.setVisible(true);
        jDesktopPane.setLayout(null);
        jf.add(jDesktopPane);
        jf.repaint();
        
        
        JInternalFrame jInternalFrame=new JInternalFrame();
        jInternalFrame.setLocation(100, 100);
        jInternalFrame.setSize(500, 300);
        jInternalFrame.setTitle("Internal frame");
        jInternalFrame.setVisible(true);
        jInternalFrame.setClosable(true);
        jInternalFrame.setResizable(true);
        jDesktopPane.add(jInternalFrame);
        jDesktopPane.repaint();
        jf.repaint();
    }
}

Output:

creating movable panel inside frame in java

0

精彩评论

暂无评论...
验证码 换一张
取 消