Hallo 
Ich hab folgendes Problem: Ich erstelle per MenuItem Neu... ein JPanel, der sich in einem scrollable TabbedPane befindet. Ich will, dass jedes mal wenn ich auf Neu.. drücke ein zusätzliches JTabbedPane neben den schon bestehenden hinzugefügt wird. Im Moment erscheint aber immer nur ein. Ich will das quasi wie bei Photoshop oder ähnliche Programme, dass wenn man neue Datei erstellt sich immer wieder ein neuen Tab öffnet wo man arbeiten kann.
Ich hab folgendes Problem: Ich erstelle per MenuItem Neu... ein JPanel, der sich in einem scrollable TabbedPane befindet. Ich will, dass jedes mal wenn ich auf Neu.. drücke ein zusätzliches JTabbedPane neben den schon bestehenden hinzugefügt wird. Im Moment erscheint aber immer nur ein. Ich will das quasi wie bei Photoshop oder ähnliche Programme, dass wenn man neue Datei erstellt sich immer wieder ein neuen Tab öffnet wo man arbeiten kann.
Java:
public class GUI extends JFrame implements ActionListener {
/**
* Erstelle neue GUI
*/
public GUI() {
initComponents();
setTitle("Layout Tool");
setSize(900,980);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void initComponents() {
menubar = new JMenuBar();
menuFile = new JMenu();
neu = new JMenuItem();
neu.setMnemonic(KeyEvent.VK_N);
neu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
neu.setText("Neu");
neu.addActionListener(this);
menuFile.add(neu);
....
}
public void actionPerformed(ActionEvent object) {
//Neu
if (object.getSource() == neu){
CreateFile create = new CreateFile();
create.addTabbedPane();
setContentPane(create);
setVisible(true);
}
.....
Java:
public class CreateFile extends JPanel implements ActionListener
{
public CreateFile()
{
initComponents();
buildLayout();
}
public void addTabbedPane(){
scrollPane.setViewportView(editPanel);
tabbedPane.addTab("Tab "+this.COUNTER ,scrollPane);
this.COUNTER++;
}
public void buildLayout(){
buildWebsitePanel();
buildLayoutPanel();
buildfixFormsPanel();
buildIndividualFormsPanel();
buildOrangeFormsPanel();
buildEditPanel();
buildHolePanel();
}
...
public void buildHolePanel(){
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
this.setBackground(darkGray);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE,0, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(websitePanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(layoutPanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(fixFormsPanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(individualFormsPanel, GroupLayout.DEFAULT_SIZE,0, Short.MAX_VALUE)
.addComponent(orangeFormsPanel, GroupLayout.DEFAULT_SIZE,0, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20 , 20, 20)
.addComponent(websitePanel)
.addGap(18, 18, 18)
.addComponent(layoutPanel)
.addGap(18, 18, 18)
.addComponent(fixFormsPanel)
.addGap(18, 18, 18)
.addComponent(individualFormsPanel)
.addGap(18, 18, 18)
.addComponent(orangeFormsPanel)
.addContainerGap())
.addComponent(tabbedPane)
);
}