Hi,
ich möchte diesen Code anpassen damit der Windowbuilder Pro es parsen kann
hat jmd ne Idee was ich dabei beachten soll / muss ???:L
Grüße
Aha
ich möchte diesen Code anpassen damit der Windowbuilder Pro es parsen kann
Java:
package addnewtabpack;
import java.awt.*;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.event.*;
public class AddNewTab implements Runnable {
JFrame frame;
JTabbedPane tabs;
ChangeListener listener;
int numTabs;
String tabname;
Integer c = new Integer (0);
public static void main(String[] args) {
System.out.println("main");
// SwingUtilities.invokeLater(new NewTabDemo());
EventQueue.invokeLater(new AddNewTab());
}
public void run() {
System.out.println("run");
listener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
addNewTab();
}
};
createMainFrame();
createFirstTab();
}
private void createFirstTab(){
System.out.println("createFirstTab");
tabs = new JTabbedPane();
JPanel firsty = new JPanel();
tabs.add(firsty, "Tab " + String.valueOf(numTabs), numTabs++);
tabs.add(new JPanel(), "+", numTabs++);
tabs.addChangeListener(listener);
JTextArea textArea = new JTextArea();
GroupLayout gl_panel = new GroupLayout(firsty);
gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(textArea, GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE));
gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(textArea, GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE));
firsty.setLayout(gl_panel);
frame.getContentPane().add(tabs, BorderLayout.CENTER);
}
private void createMainFrame() {
System.out.println("createMainFrame");
frame = new JFrame(this.getClass().getName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(new Dimension(400, 200));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void addNewTab() {
System.out.println("addNewTab");
if(c.equals(0)){
tabname = JOptionPane.showInputDialog(null, "New tab's name", "Add a new tab",JOptionPane.INFORMATION_MESSAGE);
}
if((tabname != null)&&(!tabname.isEmpty())){
c++;
int index = numTabs - 1;
if (tabs.getSelectedIndex() == index) {
JPanel newly = new JPanel();//tabs.add(newly, "Tab " + String.valueOf(index), index);
JTextArea textArea = new JTextArea();
GroupLayout gl_panel = new GroupLayout(newly);
gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(textArea, GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE));
gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(textArea, GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE));
newly.setLayout(gl_panel);
tabs.add(newly, tabname, index);
tabs.removeChangeListener(listener);
tabs.setSelectedIndex(index);
tabs.addChangeListener(listener);
numTabs++;
tabname = "";
c = 0;
}
}
}
}
Grüße
Aha