P
PowerProgrammer
Gast
Hallo!
Seit gestern beschäftige ich mich ein bisschen intensiver mit Java und bin gerade dabei, mich mit Swing auseinanderzusetzen.
Da habe ich mir testweise mal eine Klasse geschrieben:
Die ganze Klasse soll soetwas ähnliches wie ein JTabbedPane sein. Das Teil generiert ein paar Buttons und hat ein JPanel (area), auf das die Tabinhalte gepackt werden sollen. Aber es klappt noch nicht so ganz, das Umschalten will nicht. Der Code ganz am Ende (Klasse TabItem) ist das Problemkind. Die Funktion ganz unten ist der ActionHandler für den jeweiligen Button, irgendwo steckt da wohl ein Logikfehler, vermute ich.
Dankeschön!
Max
Seit gestern beschäftige ich mich ein bisschen intensiver mit Java und bin gerade dabei, mich mit Swing auseinanderzusetzen.
Da habe ich mir testweise mal eine Klasse geschrieben:
Code:
public class XExtTabbedPane extends JComponent
{
private LinkedList<TabItem> items;
private JPanel area;
private JPanel list;
XExtTabbedPane()
{
this.setLayout(new BorderLayout());
this.area = new JPanel();
add(this.area,BorderLayout.CENTER);
this.list = new JPanel();
this.list.setLayout(new BoxLayout(this.list, BoxLayout.PAGE_AXIS));
add(new JScrollPane(this.list,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),BorderLayout.LINE_START);
this.items = new LinkedList<TabItem>();
}
void addTab(String title, Component component)
{
this.addTab(title, null, component, null);
}
void addTab(String title, Icon icon, Component component)
{
this.addTab(title, icon, component, null);
}
void addTab(String title, Icon icon, Component component, String tip)
{
TabItem item = new TabItem(this, title, icon, component, tip);
}
private class TabItem implements ActionListener
{
private XExtTabbedPane tab;
public String title;
public Icon icon;
public Component component;
public String tip;
public JButton button;
TabItem(XExtTabbedPane tab, String title, Icon icon, Component component, String tip)
{
this.tab = tab;
this.title = title;
this.icon = icon;
this.component = component;
this.tip = tip;
this.button = new JButton(this.title,this.icon);
// apply to tab system
this.tab.list.add(this.button);
this.tab.items.add(this);
this.button.setPreferredSize(new Dimension(170, 50));
this.button.setMaximumSize(new Dimension(170, 50));
this.button.setToolTipText(this.tip);
if(this.tab.area.getComponentCount() == 0)
this.tab.area.add(this.component);
this.button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
this.tab.area.removeAll();
this.tab.area.add(this.component);
//this.tab.area.repaint();
}
}
}
Dankeschön!
Max