How do I open a JInternalFrame centered in a JDesktopPane?

后端 未结 5 1626
礼貌的吻别
礼貌的吻别 2021-01-05 09:21

I am adding a bunch of JInternalFrames into a JDesktopPane, as the user selects to open various features through the menus. But I would like the in

5条回答
  •  礼貌的吻别
    2021-01-05 09:53

    Add this void

    public void addCentered(Component jif) {        
        desktopPane.add(jif);
        jif.setLocation((desktopPane.getWidth()-jif.getWidth())/2, (desktopPane.getHeight()-jif.getHeight())/2);
        jif.setVisible(true);
    }
    

    and when adding the jInternalFrame call:

    addCentered(jifName);
    

提交回复
热议问题