简体   繁体   中英

How to add lines between JTable rows?

I have a JTable and could not make visible the lines between rows or maybe there is no line, I am not sure. Here is my JTable:

我的JTable

How can I make it look like this?

另一个

Here is my code:

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);
}
}

This part is inside of a class which extends JFrame.

Just put this one. I choose black color because Jtable gridlines are white as the default color.

table.setGridColor(Color.BLACK)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM