15 个解决方案
#1
用JTable的以下方法就行了:
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
#2
覆盖JTable的isCellEditable(int row, int column) 方法,直接返回false就可以了。
JTable的setShowHorizontalLines(boolean showHorizontalLines)方法应该可以去掉横线,你试试
JTable的setShowHorizontalLines(boolean showHorizontalLines)方法应该可以去掉横线,你试试
#3
不好意思,小弟初学,请问如何覆盖呢,谢谢!
#4
只读是吧?这样
jTable.setEnable(false);
也能达到目的,呵呵。
jTable.setEnable(false);
也能达到目的,呵呵。
#5
楼上的办法好象也行,呵呵。
要覆盖的话就是
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
要覆盖的话就是
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
#6
多谢大侠,不过setEnable()好像不行,因为这样鼠标选中也不行了。
我的意思是在table中鼠标双击一个单元格便可以编辑,但我想屏蔽这个功能,谢谢您了
我的意思是在table中鼠标双击一个单元格便可以编辑,但我想屏蔽这个功能,谢谢您了
#7
那就用覆盖的办法
#8
用您的方法好像不行啊?
#9
把你的代码贴上来看看
#10
/**
*@author Bob Ying
*@Test Class JTable
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
public boolean isCellEditable(int row,int column){
return false;
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new JTable(null, ColumnNames);
table.setSelectionBackground(Color.PINK);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
*@author Bob Ying
*@Test Class JTable
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
public boolean isCellEditable(int row,int column){
return false;
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new JTable(null, ColumnNames);
table.setSelectionBackground(Color.PINK);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
#11
JTable table = new JTable(null, ColumnNames);
这句话new的还是JTable,要new MyTable,做一个MyTable类,类里覆盖那个方法
这句话new的还是JTable,要new MyTable,做一个MyTable类,类里覆盖那个方法
#12
不好意思,小弟我刚学java,您能写一下吗?
#13
就是让你自己写个类MyTable,
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
#14
试一试
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
class MyTable extends JTable{
public MyTable(Vector rowData, Vector columnNames){
super(rowData,columnNames);
}
public boolean isCellEditable(int row,int column){
return false;
}
}
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new MyTable(null, ColumnNames);
table.setSelectionBackground(Color.pink);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
class MyTable extends JTable{
public MyTable(Vector rowData, Vector columnNames){
super(rowData,columnNames);
}
public boolean isCellEditable(int row,int column){
return false;
}
}
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new MyTable(null, ColumnNames);
table.setSelectionBackground(Color.pink);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
#15
谢谢大哥,小弟一定努力向您学习,感谢您的指点!
#1
用JTable的以下方法就行了:
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells.
void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.
void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.
#2
覆盖JTable的isCellEditable(int row, int column) 方法,直接返回false就可以了。
JTable的setShowHorizontalLines(boolean showHorizontalLines)方法应该可以去掉横线,你试试
JTable的setShowHorizontalLines(boolean showHorizontalLines)方法应该可以去掉横线,你试试
#3
不好意思,小弟初学,请问如何覆盖呢,谢谢!
#4
只读是吧?这样
jTable.setEnable(false);
也能达到目的,呵呵。
jTable.setEnable(false);
也能达到目的,呵呵。
#5
楼上的办法好象也行,呵呵。
要覆盖的话就是
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
要覆盖的话就是
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
#6
多谢大侠,不过setEnable()好像不行,因为这样鼠标选中也不行了。
我的意思是在table中鼠标双击一个单元格便可以编辑,但我想屏蔽这个功能,谢谢您了
我的意思是在table中鼠标双击一个单元格便可以编辑,但我想屏蔽这个功能,谢谢您了
#7
那就用覆盖的办法
#8
用您的方法好像不行啊?
#9
把你的代码贴上来看看
#10
/**
*@author Bob Ying
*@Test Class JTable
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
public boolean isCellEditable(int row,int column){
return false;
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new JTable(null, ColumnNames);
table.setSelectionBackground(Color.PINK);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
*@author Bob Ying
*@Test Class JTable
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
public boolean isCellEditable(int row,int column){
return false;
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new JTable(null, ColumnNames);
table.setSelectionBackground(Color.PINK);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
#11
JTable table = new JTable(null, ColumnNames);
这句话new的还是JTable,要new MyTable,做一个MyTable类,类里覆盖那个方法
这句话new的还是JTable,要new MyTable,做一个MyTable类,类里覆盖那个方法
#12
不好意思,小弟我刚学java,您能写一下吗?
#13
就是让你自己写个类MyTable,
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
class MyTable extends JTable{
public boolean isCellEditable(int row, int column){
return false;
}
}
#14
试一试
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
class MyTable extends JTable{
public MyTable(Vector rowData, Vector columnNames){
super(rowData,columnNames);
}
public boolean isCellEditable(int row,int column){
return false;
}
}
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new MyTable(null, ColumnNames);
table.setSelectionBackground(Color.pink);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
class TestTable extends Frame /*implements CellEditor*/ {
class MyTable extends JTable{
public MyTable(Vector rowData, Vector columnNames){
super(rowData,columnNames);
}
public boolean isCellEditable(int row,int column){
return false;
}
}
public TestTable() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JScrollPane pane = new JScrollPane();
pane.getViewport().add(buildTable(), null);
this.add(pane, BorderLayout.CENTER);
}
//接口抽象方法重载
public Object getCellEditorValue(){
return (Object)"a";
}
private JTable buildTable() {
Vector ColumnNames = new Vector();
//String[] data1 = new String[3];
Vector data1 = new Vector();
ColumnNames.add("文件名");
ColumnNames.add("大小");
ColumnNames.add("日期");
JTable table = new MyTable(null, ColumnNames);
table.setSelectionBackground(Color.pink);
table.setShowHorizontalLines(false);
table.setShowGrid(false);
//table.setCellEditor(
//table.setEnabled(false);
for (int i=0;i<10;i++){
data1.add(0,"aa"+Integer.toString(i));
((DefaultTableModel)table.getModel()).addRow(data1);
}
/*for (int i = 0; i < 10; i++) {
data1[0] = "aa " + Integer.toString(i);
data1[1] = "bb " + Integer.toString(i);
data1[2] = "cc " + Integer.toString(i);
((DefaultTableModel)table.getModel()).addRow(data1);
}*/
return table;
}
public static void main(String args[]) {
System.out.println("Starting TestTable...");
TestTable mainFrame = new TestTable();
mainFrame.setSize(400, 400);
mainFrame.setTitle("TestTable");
mainFrame.setVisible(true);
}
}
#15
谢谢大哥,小弟一定努力向您学习,感谢您的指点!