Hi, ich habe eine FixedColumnTable in mein Programm eingebaut, aber ich schaffe es einfach nicht, die Zellen editierbar zu machen.
Könnt ihr euch vielleicht mal den Code ansehen, ob ihr den Fehler findet****
mfg
Maddin
Könnt ihr euch vielleicht mal den Code ansehen, ob ihr den Fehler findet****
Java:
public class FixedColumnTable implements ChangeListener, PropertyChangeListener
{
public static JTable main;
public static JTable fixed;
private JScrollPane scrollPane;
/*
* Specify the number of columns to be fixed and the scroll pane
* containing the table.
*/
public FixedColumnTable(int fixedColumns, JScrollPane scrollPane)
{
this.scrollPane = scrollPane;
TableColumn tcol = new TableColumn();
main = ((JTable)scrollPane.getViewport().getView());
main.setAutoCreateColumnsFromModel( false );
main.addPropertyChangeListener( this );
main.setRowHeight(16);
try {
main.isCellEditable(main.getSelectedRow(), main.getSelectedColumn());
} catch (Exception e) {
}
main.setName("main");
for(int i=0; i<11; i++){
tcol = main.getColumnModel().getColumn(i);
tcol.setCellRenderer(new MyTableCellRenderer());
}
// Use the existing table to create a new table sharing
// the DataModel and ListSelectionModel
int totalColumns = main.getColumnCount();
fixed = new JTable();
fixed.setAutoCreateColumnsFromModel( false );
fixed.setModel( main.getModel() );
fixed.setSelectionModel( main.getSelectionModel() );
fixed.setFocusable( false );
fixed.setRowHeight(16);
fixed.setName("fixed");
for(int i=0; i<3; i++){
tcol = main.getColumnModel().getColumn(i);
tcol.setCellRenderer(new MyTableCellRenderer());
}
// Remove the fixed columns from the main table
// and add them to the fixed table
for (int i = 0; i < fixedColumns; i++)
{
TableColumnModel columnModel = main.getColumnModel();
TableColumn column = columnModel.getColumn( 0);
columnModel.removeColumn( column );
fixed.getColumnModel().addColumn( column );
}
// Add the fixed table to the scroll pane
fixed.setPreferredScrollableViewportSize(fixed.getPreferredSize());
scrollPane.setRowHeaderView( fixed );
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixed.getTableHeader());
// Synchronize scrolling of the row header with the main table
scrollPane.getRowHeader().addChangeListener( this );
}
public boolean CellEditable(int row, int col) {
return true;
}
/*
* Return the table being used in the row header
*/
public JTable getFixedTable()
{
return fixed;
}
//
// Implement the ChangeListener
//
public void stateChanged(ChangeEvent e)
{
// Sync the scroll pane scrollbar with the row header
JViewport viewport = (JViewport) e.getSource();
scrollPane.getVerticalScrollBar().setValue(viewport.getViewPosition().y);
}
//
// Implement the PropertyChangeListener
//
public void propertyChange(PropertyChangeEvent e)
{
// Keep the fixed table in sync with the main table
if ("selectionModel".equals(e.getPropertyName()))
{
fixed.setSelectionModel( main.getSelectionModel() );
}
if ("model".equals(e.getPropertyName()))
{
fixed.setModel( main.getModel() );
}
}
Java:
public class SearchPanelCoC extends JPanel {
private static final long serialVersionUID = 1L;
public static JPanel getSearchPanelCoC;
JDBCAdapter dtma;
public static JTable tableView;
public static Object[][] data;
/** JScrollPane scrollpane */
public static JScrollPane scrollpane;
/** JPanel searchPanelMA */
public static JPanel searchPanelCoC;
/**
* @param stmt
*/
public SearchPanelCoC(String stmt) {
searchPanelCoC = new JPanel();
searchPanelCoC.setSize(new Dimension(300,800));
dtma = new JDBCAdapter();
dtma.executeQuery(stmt);
tableView = new JTable(dtma);
tableView.setRowSelectionAllowed(true);
tableView.setColumnSelectionAllowed(true);
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); tableView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableView.getTableHeader().setReorderingAllowed(false);
MyTableModelCoC mma = new MyTableModelCoC();
tableView.setModel(mma);
tableView.getTableHeader()
.setToolTipText("Tabelle Mitarbeiter");
tableView.setSize(300, 900);
// Eigentliche Erzeugung der Tabelle
TableColumn col;
For(int i=0; i<tableView.getColumnCount; i++){
col = tableView.getColumnModel().getColumn(i);
col.setMinWidth(45);
col.setPreferredWidth(45);
col.setMaxWidth(45);
col.setCellRenderer(new MyTableCellRenderer());
}
TableRow row = null;
TableColumn cols = null;
scrollpane = new JScrollPane(tableView);
FixedColumnTable fxt = new FixedColumnTable(5, scrollpane);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollpane.getHorizontalScrollBar().setModel(CoC.scPanelRechts.getHorizontalScrollBar().getModel());
searchPanelCoC.add(scrollpane);
getSearchPanelCoC = searchPanelCoC;
CoC.component_action();
}
}
Java:
public CoC() {
super();
initialize();
}
private void initialize() {
this.setSize(1254, 614);
this.setLayout(null);
this.add(getJSplitPane(), null);
this.add(getbt_mazuteilen(), null);
this.add(getBt_calculate(), null);
this.add(getBt_maentfernen(), null);
this.add(getBt_uebernehmen(), null);
this.add(getMittePanel(), null);
stmttbl = "TRANSFORM Sum(tbl_COC.COC_Zeiteinsatz) AS SummevonZeiteinsatz BLA BLA BLA SQL Statement";
suchPanelcoc = new SearchPanelCoC(stmttbl);
panelTable.add(SearchPanelCoC.searchPanelCoC);
panelTable.setSize(new Dimension(200, 800));
this.repaint();
this.updateUI();
// […] usw.
}
mfg
Maddin