[英]How to make a table (Jtable) not editable
I've been working with some Japanese Characters, I've used unicode but I've been reading and reading how to make a JTable not editable, and still can't figure it out how to get it into my code... maybe I'm tired from 5 days of research... that's why I come to you. 我一直在使用一些日语字符,我使用过unicode,但我一直在阅读和阅读如何使JTable无法编辑,但仍然不知道如何将其放入我的代码中……也许经过5天的研究,我感到很累。这就是为什么我来找你。
Here's the code I've been using: 这是我一直在使用的代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class hiragana extends JFrame {
hiragana() {
String header [] = {" ","A","I","U","E","O"};
String data [][]= {
{" ", "\u3042", "\u3044", "\u3046", "\u3048", "\u304A"},
{"K", "\u304b", "\u304d", "\u304f", "\u3051", "\u3053"},
{"S", "\u3055", "\u3057", "\u3059", "\u305b", "\u305d"},
{"T", "\u305f", "\u3061", "\u3064", "\u3066", "\u3068"},
{"N", "\u306a", "\u306b", "\u306c", "\u306d", "\u306e"},
{"H", "\u306f", "\u3072", "\u3075", "\u3078", "\u307b"},
{"M", "\u307e", "\u307f", "\u3080", "\u3081", "\u3082"},
{"Y", "\u3084", " ","\u3086", " ", "\u3088"},
{"R", "\u3089", "\u308a", "\u308b", "\u308c", "\u308d"},
{"W", "\u308f", " ", " ", " ", "\u3092"},
{"N \'", " ", " ", "\u3093", " ", " "}
};
JTable table = new JTable(data, header);
table.setFont(new Font("Adobe Fangsong Std R",Font.BOLD,20));
table.setRowHeight(table.getRowHeight()+30);
JScrollPane scrollPane = new JScrollPane(table);
JPanel panel = new JPanel();
panel.add(scrollPane);
JFrame frame = new JFrame();
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(250,700);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
Here is the output, 这是输出,
You need to provide a suitable table model that can return false
when TableModel#isCellEditable(int row, int column)
is called. 您需要提供一个合适的表模型,当TableModel#isCellEditable(int row, int column)
时可以返回false
。
By default, the DefaultTableModel
will return true. 默认情况下, DefaultTableModel
将返回true。
Take a look at How to use Tables 看看如何使用表格
Control whether or not a cell is editable through the TableModel
. 通过TableModel
控制单元格是否可编辑。 Define your own TableModel
class by extending DefaultTableModel
. 通过扩展DefaultTableModel
定义自己的TableModel
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.