You can use JInternalFrame
to manage your registration screens.
A very simple example. Consider that you have your main screen, MainFrame
, that has a menu, something like that:
The summary code needed to create this screen would be more or less this:
public class MainFrame extends JFrame {
private static final long serialVersionUID = -4985498392168006224L;
private final JDesktopPane desktop = new JDesktopPane();
public MainFrame() {
super("Tela Principal");
final int inset = 50;
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Dimension dimension = new Dimension(screenSize.width / 3, screenSize.height / 2);
this.setBounds(inset, inset, dimension.width - inset * 2, dimension.height - inset * 2);
this.setContentPane(desktop);
this.setJMenuBar(this.createMenuBar());
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}
// esse é o cara chamado ao acessarmos o menu, ou no seu caso, clicar no botão :)
protected void createFrame() {
final UsuarioInternalFrame frame = new UsuarioInternalFrame();
frame.setVisible(true);
desktop.add(frame);
try {
frame.setSelected(true);
} catch (final PropertyVetoException e) {
// trate a exceção conforme sua necessidade
}
}
}
Obs.: as the intention is not to present the basics of swing, only the use of JInternalFrame
, I will not put how to create the menu, open the main screen, etc. =)
As we go on the menu Cadastrals -> Users, we would show a JInternalFrame
:
The menu click event, button, etc., basically creates the Internal frame that we need, the method createFrame
, of our main screen. The code of UsuarioInternalFrame
It’s simple, something like that:
public class UsuarioInternalFrame extends JInternalFrame {
private static final long serialVersionUID = -619850559630326110L;
public UsuarioInternalFrame() {
super("Usuários", true, true, true, true);
this.setSize(500, 300);
this.setLocation(30, 30);
}
}
Then you can have several Internal frames, can maximize them::
Minimize:
Finally, to customize according to your needs, as you said, to make her size stay only in the gray area of your example of Corel, term on the side menus, a Tree, etc. There are several ways to do.
This is just a basic example of how you can use JInternalFrame
, can evolve the example, customize as your need. In certain cases you can use JPanel
, but if I understand your problem, Internal frames will give you more flexibility if you can not have to customize a JPanel
.
Ah, I read it better, just add a jpanel there, and set it when you click the button. Instead of creating multiple windows (Jframes), you create containers (Jpanel), each for a different screen. Then, just alternate the visibility of each one according to the call of the buttons.
– user28595
You can use
JInternalFrame
. In certain cases you can useJPanel
, but if I understand your problem, Internal frames will give you more flexibility if you can not have to customize aJPanel
– Bruno César