簡體   English   中英

如何在JTable行之間添加行?

[英]How to add lines between JTable rows?

我有一個JTable,無法使行之間的線可見,或者也許沒有線,我不確定。 這是我的JTable:

我的JTable

如何使它看起來像這樣?

另一個

這是我的代碼:

public class NodePropertyWindow extends JFrame{

public NodePropertyWindow(CytoVisProject cytoVisProject, CyNode node){
    this.cytoVisProject = cytoVisProject;
    this.adapter = cytoVisProject.getAdapter();
    this.node = node;
    this.setMinimumSize(new Dimension(400, 400));
    this.setPreferredSize(new Dimension(400,400));
    this.setTitle("Node Property Window");
    this.setVisible(true);
    this.initializeTable();
}

public void initializeTable(){
    CyApplicationManager manager = this.adapter.getCyApplicationManager();
    CyNetworkView networkView = manager.getCurrentNetworkView();
    CyNetwork network = networkView.getModel();
    CyTable cyTable = network.getDefaultNodeTable();

    FilterUtil filterUtil = new FilterUtil(network, cyTable);
    Map<String, Object> sampleRow = cyTable.getAllRows().get(filterUtil.findIndex(filterUtil.getAllNodes(), node)).getAllValues();
    Collection<Object> values = sampleRow.values();
    Set<String> attributeNames = sampleRow.keySet();

    String[] columnNames = {"Attribute Name", "Value"};
    this.data = new Object[values.size()][2];
    Object[] attributeNamesObjects = attributeNames.toArray();
    Iterator iterator = values.iterator();

    for(i=0; i<values.size(); i++){
        this.data[i][0] = attributeNamesObjects[i];
        Object object = iterator.next();
        this.data[i][1] = object;

    }
    // Above part is about the content of JTable
    TableModel model = new DefaultTableModel(this.data, columnNames){
        public boolean isCellEditable(int row, int column){
            return false;
        }
    };

    this.table = new JTable(this.data, columnNames);
    this.table.setModel(model);
    this.table.setPreferredScrollableViewportSize(new Dimension(500,300));
    this.table.setFillsViewportHeight(true);
    this.table.setLayout(new BorderLayout());
    Container container = new Container();
    container.setLayout(new BorderLayout());
    container.add(table.getTableHeader(), BorderLayout.PAGE_START);
    container.add(table, BorderLayout.CENTER);
    this.add(container);
}
}

這部分在擴展JFrame的類中。

只是把這個。 我選擇黑色是因為Jtable網格線是白色作為默認顏色。

table.setGridColor(Color.BLACK)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM