社区
Java EE
帖子详情
请问如何将JTable像JButton一样置灰
llaabb
2005-01-11 11:28:07
JTable在JScrollPane中,请问是否可以将它像对JButton一样置灰?如果可以如何实现?
JScrollPane jp = new JScrollPane();
JTable jt = new JTable();
jp.getViewport().add(jt, null);
我用这个语句
jt.setEnabled(false);
可是滚动条还是可用,同时JTable上的列宽也可以调整。
我想将它置灰,不能点击。
谢谢!
...全文
152
11
打赏
收藏
请问如何将JTable像JButton一样置灰
JTable在JScrollPane中,请问是否可以将它像对JButton一样置灰?如果可以如何实现? JScrollPane jp = new JScrollPane(); JTable jt = new JTable(); jp.getViewport().add(jt, null); 我用这个语句 jt.setEnabled(false); 可是滚动条还是可用,同时JTable上的列宽也可以调整。 我想将它置灰,不能点击。 谢谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
BasaraTracy
2005-01-13
打赏
举报
回复
jt.setEnabled(false);的意思是不允许选择表格的操作
JScrollPane 的滚动条置灰不大可能吧,如果这样不如不加滚动条了
llaabb
2005-01-13
打赏
举报
回复
楼上的,请问怎样将JScrollPane的滚动条禁掉,显示区置灰
不徻写代码
2005-01-13
打赏
举报
回复
JScrollPane的滚动条禁掉,显示区置灰
popufig
2005-01-13
打赏
举报
回复
我只知道可以设定JTable的Cell不可编辑,但是不知道还可以置为灰色
llaabb
2005-01-13
打赏
举报
回复
这个问题还没解决呢,请高手帮忙一下了
谢谢
llaabb
2005-01-12
打赏
举报
回复
同时使用了
jp.setEnabled(false);
jt.setEnabled(false);
还是不行啊
gwang119
2005-01-12
打赏
举报
回复
是不是应该 :jp.setEnabled(false);
llaabb
2005-01-12
打赏
举报
回复
好像TableModel没有isCellrender这个方法吧,而且TableModel的代码已经封装,也不能随便改了
dulang200x
2005-01-12
打赏
举报
回复
实现模型里的isCellrender() 方法,返回false ,
6应该就是不可编辑了吧,
1
llaabb
2005-01-12
打赏
举报
回复
请高手帮忙啊,谢谢了
llaabb
2005-01-11
打赏
举报
回复
有没有高手回答一下呀
Swing中
JTABLE
中添加
JBUTTON
控件
swing 中
JTABLE
中添加控件的例子 可以引申出添加很多控件
JTable
表格单元加按钮,并且响应点击事件Demo.rar
用改写 DefaultCellEditor 和 TableCellRenderer的方法实现,主要代码: table.getColumnModel().getColumn(2).setCellEditor(new MyButtonEditor()); table.getColumnModel().getColumn(2).setCellRenderer(new MyButtonRender());
使用 AbstractTableModel 构建Table 在表格中添加
JButton
按钮
使用 AbstractTableModel 构建Table 在表格中添加
JButton
按钮,之前在网上找了2天没有找到好用的程序,最终终于找到一个好用的例子。 不要使,我退你们分。。 sing the Swing
JTable
class can quickly become a sticky business when you want to customize it to your specific needs. First you must become familiar with how the
JTable
class is organized. Individual cells are rendered by TableCellRenderer implementations. The table contents are represented by an implementation of the TableModel interface. By default,
JTable
uses DefaultTableCellRenderer to draw its cells. DefaultTableCellRenderer recognizes a few primitive types, rendering them as strings, and can even display Boolean types as checkboxes. But it defaults to displaying the value returned by toString() for types it does not specifically handle. You have to provide your own TableCellRenderer implementation if you want to display buttons in a
JTable
. The TableCellRenderer interface contains only one method, getTableCellRendererComponent(...), which returns a java.awt.Component that knows how to draw the contents of a specific cell. Usually, getTableCellRendererComponent() will return the same component for every cell of a column, to avoid the unnecessary use of extra memory. But when the contents of a cell is itself a component, it is all right to return that component as the renderer. Therefore, the first step towards having
JButton
s display correctly in a
JTable
is to create a TableCellRenderer implementation that returns the
JButton
contained in the cell being rendered. In the accompanying code listing,
JTable
ButtonRenderer demonstrates how to do this. Even after creating a custom TableCellRenderer, you're still not done. The TableModel associated with a given
JTable
does not only keep track of the contents of each cell, but it also keeps track of the class of data stored in each column. DefaultTableModel is designed to work with DefaultTableCellRenderer and will return java.lang.String.class for columns containing data types that it does not specifically handle. The exact method that does this is getColumnClass(int column). Your second step is to create a TableModel implementation that returns
JButton
.class for cells that contain
JButton
s.
JTable
ButtonModel shows one way to do this. It just returns the result of getClass() for each piece of cell data. At this point, you're almost done, but not quite. What's the use of putting a
JButton
in a
JTable
if you can't press the darn thing? By default,
JTable
will not forward mouse events to components contained in its cells. If you want to be able to press the buttons you add to
JTable
, you have to create your own MouseListener that forwards events to the
JButton
cells.
JTable
ButtonMouseListener demonstrates how you could do this.
如何在
JTable
的单元格里添加图片,Button组件,Label组件等等组件
添加组件后,在组件上添加图片 1.设
置
Table的Model这个需要重写AbstractTableModel类, 2.设
置
Table的DefaultRenderer,这个根据个人需要选择将要添加到Table的cell里的 组件(
JButton
,JLable...)继承相应的组件,并且implements TableCellRenderer,图片的方式是,将图片添加该组件中就可以了,具体方式是加入到重写的方法中.this.setIcon("path"),就可以了 3.设
置
Table的DefaultEditor,这个需要extends AbstractCellEditor implements TableCellEditor,ActionListener
学生成绩管理系统源代码(java)+Swing窗口程序+mysql数据库
开发工具:eclipse 数据库:mysql 数据库参数配
置
类:MysqlForm 程序启动主类:MainForm 数据库脚本文件:grade_manage.sql 使用技术:mysql数据库,java数据库技术,swing组件,
jtable
,
jbutton
等组件使用。 主要功能: 老师权限: 1.新增老师资料,修改老师资料,删除老师资料,查询老师信息; 2.新增学生成绩,修改学生成绩,删除学生成绩,查看学生成绩; 学生权限: 1.按学号查询学生成绩; 2.按班级,科目查询学生成绩; 3.按班级,科目及分数段查询学生成绩;
Java EE
67,515
社区成员
225,878
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章