我一直在使用某些日语字符,我使用过unicode,但是我一直在阅读和阅读如何使JTable不可编辑,但仍无法弄清楚如何将其添加到我的代码中. ..也许我对5天的研究感到累了,这就是为什么我来找你.
这是我一直在使用的代码:
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); } }这是输出,
解决方案
您需要提供一个合适的表模型,当调用TableModel#isCellEditable(int row, int column)时可以返回false.
默认情况下,DefaultTableModel将返回true.
看看如何使用表
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.
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.
By default, the DefaultTableModel will return true.
Take a look at How to use Tables
更多推荐
如何使表(Jtable)不可编辑
发布评论