我正在用Java编写应用程序,我遇到的问题是JTabbedPane填充了一个包含2个JPanel的JLayeredPane。我需要有两个不同的页面(配置文件和编辑配置文件),以便配置文件选项卡显示配置文件,配置文件JPanel中的“编辑配置文件”按钮将显示另一个带编辑配置文件的JPanel。首先,这是一个可以接受的想法吗?
我有使用SpringLayout Manager的Profile JPanel和editProfile JPanel。我已经读过JLayeredPane不能用于LayoutManagers,但是在JPanels上使用它应该可以工作,对吗?我有一些示例代码,我在下面写的,我认为应该工作,但我得到的是一个空白的选项卡。任何帮助都会很棒。感谢。
public class rework extends UserInterface {
private static SpringLayout infoLocation = new SpringLayout();
private static SpringLayout editLocation = new SpringLayout();
private static JPanel infoPane = new JPanel(infoLocation);
private static JPanel editPane = new JPanel(editLocation);
private static JLayeredPane manager = new JLayeredPane();
public static JLayeredPane displayScreen() {
JLabel lblProfile = new JLabel("Profile");
JLabel lblEditProfile = new JLabel("Edit Profile");
infoPane.add(lblProfile, SpringLayout.WEST);
editPane.add(lblEditProfile, SpringLayout.WEST);
infoLocation.putConstraint(SpringLayout.WEST, lblProfile, 5, SpringLayout.WEST, infoPane);
infoLocation.putConstraint(SpringLayout.NORTH, lblProfile, 5, SpringLayout.NORTH, infoPane);
editLocation.putConstraint(SpringLayout.WEST, lblEditProfile, 5, SpringLayout.WEST, editPane);
editLocation.putConstraint(SpringLayout.NORTH, lblEditProfile, 5, SpringLayout.NORTH, editPane);
manager.add(editPane, JLayeredPane.DEFAULT_LAYER);
manager.add(infoPane, JLayeredPane.PALETTE_LAYER);
return manager;
}
}