Hallo Leute!
Hab mal was ganz was anderes:
Ich habe eine Client-Applikation (RMI) in der 2 Tabellen und ein 'header' mit 2 Labels und einem Spinner ist.
Das Problem:
Ich kann den Spinner nicht anwählen bzw. den Wert darin nicht verändern.
Hab schon einige Sachen ausprobiert...
Wenn ich den Spinner nicht in den Header gebe, funktioniert er. Weiß jemand hilfe?
*Edit:*
JNumberSpinner ist meine Eigenkreation, da ich dachte es liegt am Spinner, funktioniert aber genauso wie der Spinner.
greez
THEJS
Hab mal was ganz was anderes:
Ich habe eine Client-Applikation (RMI) in der 2 Tabellen und ein 'header' mit 2 Labels und einem Spinner ist.
Das Problem:
Ich kann den Spinner nicht anwählen bzw. den Wert darin nicht verändern.
Hab schon einige Sachen ausprobiert...
Wenn ich den Spinner nicht in den Header gebe, funktioniert er. Weiß jemand hilfe?
Java:
public class WS_Liefertermine extends BusinessPanel implements DeliveryTableInterface
{
private static final long oneDayInMillis = (60*60*24*1000);
private ReadOnlyTableModel dtm = new ReadOnlyTableModel();
private JTable table = new JTable(dtm);
private JTable ordertable = new JTable(new ReadOnlyTableModel());
private JLabel label1;
private JNumberSpinner spinner;
private JPanel northCenterPanel;
private JPanel northEastPanel;
private JPanel centerPanel = new JPanel();
private JPanel northPanel = new JPanel();
private JLabel label = new JLabel("Kalenderwoche: ");
private ArrayList<UpdateActionBuffer> updatedDates = new ArrayList<UpdateActionBuffer>();
protected static Calendar myCalendar = Calendar.getInstance();
protected static boolean readOnly = false;
private Object[] columnIdentifier = new Object[] {
"manualproductionid",
"ArtikelNr",
"Beschreibung",
"Montag (XX.XX.XXXX)",
"Dienstag (XX.XX.XXXX)",
"Mittwoch (XX.XX.XXXX)",
"Donnerstag (XX.XX.XXXX)",
"Freitag (XX.XX.XXXX)",
"Gesamt (KWX)",
"isreadonly"
};
private Date dateOnMonday;
public WS_Liefertermine(String[] args)
{
initialize();
}
private void initialize()
{
spinner = new JNumberSpinner(myCalendar.get(Calendar.WEEK_OF_YEAR), myCalendar.get(Calendar.WEEK_OF_YEAR)-10, myCalendar.get(Calendar.WEEK_OF_YEAR)+10, 1);
label1 = new JLabel();
northPanel = new JPanel();
northCenterPanel = new JPanel();
northEastPanel = new JPanel();
this.setLayout(new BorderLayout());
this.add(northPanel, BorderLayout.PAGE_START);
this.add(centerPanel, BorderLayout.CENTER);
spinner.setPreferredSize(new Dimension(50, 20));
spinner.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
//...
}
});
myCalendar.setFirstDayOfWeek(Calendar.MONDAY);
myCalendar.setTimeInMillis(System.currentTimeMillis());
northPanel.setPreferredSize(new Dimension(200, 60));
northCenterPanel.setPreferredSize(new Dimension(200, 60));
northCenterPanel.add(label);
northCenterPanel.add(spinner);
northPanel.setLayout(new BorderLayout());
northPanel.add(northCenterPanel, BorderLayout.CENTER);
northPanel.add(northEastPanel, BorderLayout.EAST);
northEastPanel.setPreferredSize(new Dimension(200, 60));
northEastPanel.setLayout(new BorderLayout());
label1.setFont(new Font("Arial", Font.PLAIN, 54));
northEastPanel.add(label1, BorderLayout.CENTER);
centerPanel.setLayout(new BorderLayout());
JPanel centernorthpanel = new JPanel();
centernorthpanel.setLayout(new BorderLayout());
centernorthpanel.add(table.getTableHeader(), BorderLayout.PAGE_START);
centernorthpanel.add(new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
centernorthpanel.setPreferredSize(new Dimension(12, 120));
JPanel centercenterpanel = new JPanel();
centercenterpanel.setLayout(new BorderLayout());
centercenterpanel.add(ordertable.getTableHeader(), BorderLayout.PAGE_START);
centercenterpanel.add(new JScrollPane(ordertable), BorderLayout.CENTER);
centerPanel.add(centernorthpanel, BorderLayout.NORTH);
centerPanel.add(centercenterpanel, BorderLayout.CENTER);
table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
table.getTableHeader().setReorderingAllowed(false);
table.setAutoCreateRowSorter(true);
ordertable.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
ordertable.getTableHeader().setReorderingAllowed(false);
ordertable.setAutoCreateRowSorter(true);
table.getColumnModel().addColumnModelListener(new TableColumnModelAdapter()
{
@Override
public void columnSelectionChanged(ListSelectionEvent e)
{
if(table.getSelectedColumn() > 8)
{
table.getColumnModel().getSelectionModel().setSelectionInterval(table.getSelectedColumn()-1, table.getSelectedColumn()-1);
} else if(table.getSelectedColumn() < 1)
{
table.getColumnModel().getSelectionModel().setSelectionInterval(table.getSelectedColumn()+1, table.getSelectedColumn()+1);
}
}
});
ordertable.getColumnModel().addColumnModelListener(new TableColumnModelAdapter()
{
@Override
public void columnSelectionChanged(ListSelectionEvent e)
{
if(ordertable.getSelectedColumn() > 8)
{
ordertable.getColumnModel().getSelectionModel().setSelectionInterval(ordertable.getSelectedColumn()-1, ordertable.getSelectedColumn()-1);
} else if(ordertable.getSelectedColumn() < 1)
{
ordertable.getColumnModel().getSelectionModel().setSelectionInterval(ordertable.getSelectedColumn()+1, ordertable.getSelectedColumn()+1);
}
}
});
spinner.getChangeListeners()[0].stateChanged(new ChangeEvent(spinner));
ordertable.getRowSorter().toggleSortOrder(2);
table.getRowSorter().toggleSortOrder(2);
try
{
DeliveryDateService dds = WorkshopClient.getDeliveryDateService();
DeliveryDateUpdateActionImpl action = new DeliveryDateUpdateActionImpl()
{
private static final long serialVersionUID = 1L;
@Override
public void updateAction(int productid, Date affectedDate,
boolean wasManualChange, int newValue) throws RemoteException
{
updatedDates.add(new UpdateActionBuffer(productid, affectedDate, wasManualChange, newValue));
localUpdateAction(productid, affectedDate, wasManualChange, newValue);
}
};
dds.addUpdateListener(WorkshopClient.getClientInformation(), action);
} catch (RemoteException e1)
{
// TODO: Logging
e1.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
spinner.requestFocus();
}
protected void localUpdateAction(int productid, Date affectedDate,
boolean wasManualChange, int newValue)
{
try
{
Calendar c = Calendar.getInstance();
c.setTimeInMillis(affectedDate.getTime());
if(c.get(Calendar.WEEK_OF_YEAR) == myCalendar.get(Calendar.WEEK_OF_YEAR))
{
boolean found = false;
if(wasManualChange)
{
for(int i=0;i<table.getRowCount();i++)
{
if(table.getValueAt(i, 0).toString().equals(String.valueOf(productid)))
{
table.setValueAt("1_" + newValue, i, c.get(Calendar.DAY_OF_WEEK)+1);
table.setValueAt("1_" + getSum(table, i), i, 8);
found = true;
}
}
} else
{
for(int i=0;i<ordertable.getRowCount();i++)
{
if(ordertable.getValueAt(i, 0).toString().equals(String.valueOf(productid)))
{
ordertable.setValueAt("1_" + newValue, i, c.get(Calendar.DAY_OF_WEEK)+1);
ordertable.setValueAt("1_" + getSum(ordertable, i), i, 8);
found = true;
}
}
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
private void setColumnSizes(JTable table)
{
Color c_yellow = new Color(255,255,153);
Color c_lila = new Color(204,204,255);
table.getColumnModel().getColumn(0).setMinWidth(0);
table.getColumnModel().getColumn(0).setPreferredWidth(0);
table.getColumnModel().getColumn(0).setMaxWidth(0);
table.getColumnModel().getColumn(1).setMinWidth(74);
table.getColumnModel().getColumn(1).setPreferredWidth(74);
table.getColumnModel().getColumn(1).setMaxWidth(74);
table.getColumnModel().getColumn(1).setCellEditor(new ArticleSelectionEditor());
table.getColumnModel().getColumn(3).setMinWidth(115);
table.getColumnModel().getColumn(3).setPreferredWidth(115);
table.getColumnModel().getColumn(3).setMaxWidth(115);
table.getColumnModel().getColumn(3).setCellRenderer(new DefaultColorRenderer(c_yellow));
table.getColumnModel().getColumn(4).setMinWidth(120);
table.getColumnModel().getColumn(4).setPreferredWidth(120);
table.getColumnModel().getColumn(4).setMaxWidth(120);
table.getColumnModel().getColumn(4).setCellRenderer(new DefaultColorRenderer(c_lila));
table.getColumnModel().getColumn(5).setMinWidth(125);
table.getColumnModel().getColumn(5).setPreferredWidth(125);
table.getColumnModel().getColumn(5).setMaxWidth(125);
table.getColumnModel().getColumn(5).setCellRenderer(new DefaultColorRenderer(c_yellow));
table.getColumnModel().getColumn(6).setMinWidth(135);
table.getColumnModel().getColumn(6).setPreferredWidth(135);
table.getColumnModel().getColumn(6).setMaxWidth(135);
table.getColumnModel().getColumn(6).setCellRenderer(new DefaultColorRenderer(c_lila));
table.getColumnModel().getColumn(7).setMinWidth(115);
table.getColumnModel().getColumn(7).setPreferredWidth(115);
table.getColumnModel().getColumn(7).setMaxWidth(115);
table.getColumnModel().getColumn(7).setCellRenderer(new DefaultColorRenderer(c_yellow));
table.getColumnModel().getColumn(8).setMinWidth(90);
table.getColumnModel().getColumn(8).setPreferredWidth(90);
table.getColumnModel().getColumn(8).setMaxWidth(90);
table.getColumnModel().getColumn(8).setCellRenderer(new DefaultColorRenderer(c_lila));
table.getColumnModel().getColumn(9).setMinWidth(0);
table.getColumnModel().getColumn(9).setPreferredWidth(0);
table.getColumnModel().getColumn(9).setMaxWidth(0);
}
@Override
public void refreshTableData()
{
dtm.setRowCount(0);
((DefaultTableModel)ordertable.getModel()).setRowCount(0);
try
{
//...
} catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public int getCurrentCalendarWeek()
{
return myCalendar.get(Calendar.WEEK_OF_YEAR);
}
@Override
public boolean isReadOnly()
{
return true;
}
@Override
public Date getDateOnMonday()
{
return dateOnMonday;
}
@Override
public void openSettings(){}
}
*Edit:*
JNumberSpinner ist meine Eigenkreation, da ich dachte es liegt am Spinner, funktioniert aber genauso wie der Spinner.
greez
THEJS