我正在使用 netbeans,我用 netbeans 创建了一个JFrame
表单,它创建了以下类,我也编辑过:
public class Gui extends javax.swing.JFrame {
public Gui() {
initComponents();
this.setVisible(false);
this.setLocationRelativeTo(null); // finestra al centro dello schermo
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 804, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 536, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
}
之后,我创建了一个JPanel
要添加到以前的类Gui
JFrame
:
public class Gui_JTabbedPane extends JPanel {
public Gui_JTabbedPane() {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
JComponent panel1 = makeTextPanel("Try");
tabbedPane.addTab("Try", panel1, "Does nothing");
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
add(tabbedPane);
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
protected JComponent makeTextPanel(String text) {
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
}
所以在我的主要课程中,我这样做了:
Gui_JTabbedPane tabbedpane = new Gui_JTabbedPane();
Gui gui = new Gui();
gui.add( tabbedpane );
gui.setVisible(true);
问题是它只显示了JFrame
(Gui) 而JPanel
里面没有 ('GuiJTabbedPane`),正如我想要的那样。
相反,如果我编辑第一个类(Gui)initComponents();
,JFrame
则不会显示,但这次JPanel
会。
如何仅使用/编辑这两个类来解决它?
谢谢