如何往JTable的单元格中添加一个按钮

 我来答
匿名用户
2016-12-08
展开全部
Object [][] data={ {null, null, null, null,null,null,1}, {2, 3, 4, 5, 6, 7, 8}, {9, 10, 11, 12, 13, 14, 15}, {16, 17, 18, 19, 20, 21, 22}, {23, 24, 25, 26, 27, 28, 29}, {30, 31, null, null, null, null,null} }; String [] head={ "日", "一", "二", "三","四","五","六" }; JTable jTable1=new JTable(data,head); jTable1.setRowHeight(40); jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); JScrollPane jScrollPane1=new JScrollPane(); jTable1.setCellSelectionEnabled(true); jTable1.setFont(new Font("SimSun", 0, 20)); jTable1.getTableHeader().setFont(new Font("SimSun",0, 20)); jTable1.getTableHeader().setReorderingAllowed(false); jTable1.getTableHeader().setResizingAllowed(false); jTable1.setEnabled(false); TableColumn column=null; for(int i=0;i<7;i++){ column=jTable1.getColumnModel().getColumn(i); column.setPreferredWidth(60); } DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if((column == 0&&row!=3)column == 6(column == 3&&row==3)) setBackground(new java.awt.Color(255, 255, 0)); else setBackground(new Color(255,255,255)); return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }; for(int i=0;i<7;i++){ jTable1.getColumn(head[i]).setCellRenderer(tcr); } jScrollPane1.setViewportView(jTable1);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式