如何使表(Jtable)不可编辑

编程入门 行业动态 更新时间:2024-10-23 03:22:01
本文介绍了如何使表(Jtable)不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在使用某些日语字符,我使用过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)不可编辑

本文发布于:2023-11-23 01:24:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑   Jtable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!