右键单击添加的 JTable 组件未找到“Table Contents...”
时间: 2023-09-30 14:05:27 浏览: 64
如果您在 WindowBuilder 中右键单击添加的 JTable 组件未找到“Table Contents...”选项,您可以尝试按照以下步骤操作:
1. 右键单击 JTable 组件并选择“Properties”。
2. 在“Properties”窗口中,选择“model”属性。
3. 单击“...”按钮以编辑模型属性。
4. 在“Edit Property Value”对话框中,选择“Custom Creation”选项卡,并在其中添加您的 TableModel 实现代码。
5. 在代码中实现 TableModel 接口中的方法,并为 JTable 提供正确的数据。
以下是一个简单的示例代码,演示如何在 WindowBuilder 中实现 TableModel 接口:
```java
import javax.swing.table.AbstractTableModel;
public class MyTableModel extends AbstractTableModel {
private Object[][] data = {{"John", "Doe", 30}, {"Jane", "Doe", 25}, {"Bob", "Smith", 40}};
private String[] columnNames = {"First Name", "Last Name", "Age"};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
```
在此示例中,我们实现了 TableModel 接口中的方法,并为 JTable 提供了一个简单的数据模型。要将此模型应用于 WindowBuilder 中的 JTable 组件,您只需在“Edit Property Value”对话框中选择“Custom Creation”选项卡,并将上述代码复制粘贴到该选项卡中即可。然后,您可以在 JTable 中查看并编辑来自 MyTableModel 的数据。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)