[英]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. 我有一个JTable,无法使行之间的线可见,或者也许没有线,我不确定。 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. 这部分在扩展JFrame的类中。
Just put this one. 只是把这个。 I choose black color because Jtable gridlines are white as the default color.
我选择黑色是因为Jtable网格线是白色作为默认颜色。
table.setGridColor(Color.BLACK)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.