我有一个JXTreeTable
结构,有5列,我必须使最后一个(布尔类型)可编辑。
我已经尝试了任何东西,谷歌搜索了几个小时,我在这里搜索了SO,我发现了类似的问题,但他们没有帮助我的具体情况(那是因为他们给出了JTrees
或JTables
的问题的答案简单的JXTreeTable
而不是getColumnClass(int column)
组件。)
我已经在树模型中指定了JCheckBoxes
方法,以使最后一列中的布尔单元格呈现为isCellEditable(Object node, int column)
,并使用DefaultMutableTreeNode albero = initTree();
final JXTreeTable binTree = new JXTreeTable(new MyTreeModel(albero));
Highlighter highligher = HighlighterFactory.createSimpleStriping(HighlighterFactory.BEIGE);
binTree.setHighlighters(highligher);
binTree.setShowGrid(false);
binTree.setShowsRootHandles(true);
binTree.setEditable(true);
configureCommonTableProperties(binTree);
binTree.setTreeCellRenderer(new TreeTableCellRenderer());
方法返回列和让它可编辑。
我实际上是用一个从数据库中读取文件的查询来填充该列,并在满足要求时将其中一些单元格设置为true。
以下是我的GUI实际情况的链接:
如果您需要我的代码片段,请告诉我,并在建议中表示感谢!
这是树形结构:
public class MyTreeModel extends AbstractTreeTableModel {
private String [] titles = {"Utente", "Radice Menù", "Programma", "Descrizione", "Abilitazione"};
public MyTreeModel(DefaultMutableTreeNode root) {
super(root);
}
@Override
public String getColumnName(int column) {
if (column < titles.length)
return (String) titles[column];
else
return "";
}
@Override
public boolean isCellEditable(Object node, int column) {
return column == 4;
}
@Override
public int getColumnCount() {
return titles.length;
}
@Override
public Class getColumnClass(int column) {
if (column == 4 )
return Boolean.class;
else
return String.class;
}
@Override
public Object getValueAt(Object arg0, int arg1) {
if(arg0 instanceof TableRowData) {
TableRowData data = (TableRowData)arg0;
if(data != null) {
switch(arg1) {
case 0: return data.getUtente();
case 1: return data.getRott();
case 2: return data.getProgramma();
case 3: return data.getDescrizione();
case 4: return data.getFlag();
}
}
}
}
if(arg0 instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode dataNode = (DefaultMutableTreeNode)arg0;
TableRowData data = (TableRowData)dataNode.getUserObject();
if(data != null) {
switch(arg1) {
case 0: return data.getUtente();
case 1: return data.getRott();
case 2: return data.getProgramma();
case 3: return data.getDescrizione();
case 4: return data.getFlag();
}
}
}
@Override
public Object getChild(Object arg0, int arg1) {
if(arg0 instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode nodes = (DefaultMutableTreeNode)arg0;
return nodes.getChildAt(arg1);
}
return null;
}
@Override
public int getChildCount(Object arg0) {
if(arg0 instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode nodes = (DefaultMutableTreeNode)arg0;
return nodes.getChildCount();
}
return 0;
}
@Override
public int getIndexOfChild(Object arg0, Object arg1) {
if(arg0 instanceof DefaultMutableTreeNode && arg1 instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) arg0;
return parent.getIndex((DefaultMutableTreeNode) arg1);
}
return 0;
}
@Override
public boolean isLeaf(Object node) {
return getChildCount(node) == 0;
}
return null;
}
TreeModel的定义:
public class TableRowData {
private String utente = null;
private String rott;
private String programma;
private boolean flag;
private String descrizione;
private boolean isRoot;
public TableRowData(String Utente, String Rott, String Programma, String Descrizione, Boolean Flag, boolean isLeaf) {
this.utente = Utente;
this.rott = Rott;
this.programma = Programma;
this.flag = Flag;
this.descrizione = Descrizione;
this.isRoot = isLeaf;
}
/**
* @return the isRoot
*/
public boolean isRoot() {
return isRoot;
}
/**
* @param isRoot the isRoot to set
*/
public void setRoot(boolean isLeaf) {
this.isRoot = isLeaf;
}
public String getUtente() {
return utente;
}
public void setUtente(String Utente) {
this.utente = Utente;
}
public String getRott() {
return rott;
}
public void setRott(String Rott) {
this.rott = Rott;
}
public String getProgramma() {
return programma;
}
public void setProgramma(String Programma) {
this.programma = Programma;
}
public Boolean getFlag() {
return flag;
}
public void setFlag(Boolean Flag) {
this.flag = Flag;
}
public String getDescrizione() {
return descrizione;
}
public void setDescrizione(String descrizione) {
this.descrizione = descrizione;
}
}
实现行数据的get / set方法的类:
SELECT MASTER_CONTAINER_ID
FROM CONTAINER_HISTORY A
WHERE ACTION_TS IN
(SELECT MIN(ACTION_TS)
FROM (SELECT *
FROM CONTAINER_HISTORY
WHERE CONTAINER_ID = 'abc'
AND PUTAWAY_DATE IN
(SELECT MIN(PUTAWAY_DATE)
FROM CONTAINER_HISTORY
WHERE CONTAINER_ID = 'abc' )))
AND CONTAINER_ID = 'abc'
ORDER BY ACTION_TS DESC;