J
Johnson
Gast
Hi@all,
ich habe mir eine Demofunktion geschrieben, die mir beim Wechseln in der Navigation (mittels JComboBox) jeweils etwas anderes auf dem JPanel anzeigen sollte.
Leider funktioniert es nicht.
Was hab ich falsch gemacht? Hier ist meine Funktion:
Hatte schon versucht was mit repaint zu machen. Glaub das ist jetzt vielleicht auch ein bischen viel. Gebracht hats aber leider nix!
ich habe mir eine Demofunktion geschrieben, die mir beim Wechseln in der Navigation (mittels JComboBox) jeweils etwas anderes auf dem JPanel anzeigen sollte.
Leider funktioniert es nicht.
Was hab ich falsch gemacht? Hier ist meine Funktion:
Code:
public static JPanel demo(){
//COLLECTION WITH CONNECTION
Connection cn;
cn = new DB_Object().get_Connection();
DB_Statistics db = new DB_Statistics();
Collection<DTO_Statistics> col = null;
//Panels
JPanel panel = new JPanel(new BorderLayout());
JPanel navi = new JPanel(new GridLayout(1,5));
JComboBox jComboBox = null;
//Combobox_Model
ComboBoxModel jComboBox_GenderModel = new DefaultComboBoxModel
(
new String[] {
"Religion",
"Politik",
"Geschlecht",
"Sternzeichen"
}
);
//Combobox
jComboBox = new JComboBox();
jComboBox.setModel(jComboBox_GenderModel);
jComboBox.setEditable(false);
//Action
jComboBox.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Object oldItem = null;
JComboBox cb = (JComboBox)e.getSource();
// Get the new item
int newIndex = cb.getSelectedIndex();
Object newItem = cb.getSelectedItem();
// Determine if different from previously selected item
boolean same = newItem.equals(oldItem);
if(!same)
oldItem = newItem;
if ("comboBoxEdited".equals(e.getActionCommand())) {
// User has typed in a string; only possible with an editable combobox
} else if ("comboBoxChanged".equals(e.getActionCommand())) {
// User has selected an item; it may be the same item
}
System.out.println(newIndex + newItem.toString());
FreeChartStatistics fcs = new FreeChartStatistics();
fcs.setNewIndex(newIndex);
fcs.setName(newItem.toString());
}
});
navi.add(jComboBox);
navi.setSize(200, 22);
panel.add(navi, BorderLayout.NORTH);
//FREECHART's
JPanel charts = new JPanel(new GridLayout(1,1));
FreeChartStatistics fcs = new FreeChartStatistics();
if(fcs.getNewIndex() == 0){
col = db.userReligion_statisticMethod(cn);
charts = FreeChartStatistics.PieChart3D_Religion(fcs.getName(), charts, col);
panel.add(charts, BorderLayout.CENTER);
charts.repaint();
panel.repaint();
}
if(fcs.getNewIndex() == 1){
col = db.userPolitical_statisticMethod(cn);
charts = FreeChartStatistics.PieChart3D(fcs.getName(), charts, col);
panel.add(charts, BorderLayout.CENTER);
charts.repaint();
panel.repaint();
}
if(fcs.getNewIndex() == 2){
col = db.userSex_statisticMethod(cn);
charts = FreeChartStatistics.PieChart3D(fcs.getName(), charts, col);
panel.add(charts, BorderLayout.CENTER);
charts.repaint();
panel.repaint();
}
if(fcs.getNewIndex() == 3){
col = db.userZodiacSign_statisticMethod(cn);
charts = FreeChartStatistics.PieChart3D(fcs.getName(), charts, col);
panel.add(charts, BorderLayout.CENTER);
charts.repaint();
panel.repaint();
}
new DB_Object().close_Connection(cn);
charts.repaint();
panel.repaint();
return panel;
}
Hatte schon versucht was mit repaint zu machen. Glaub das ist jetzt vielleicht auch ein bischen viel. Gebracht hats aber leider nix!