- 浏览: 725439 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
lingsuch:
Android网络连接判断与处理 -
月光照着我:
写的不错,作为笔记了
Android中LayoutInflater的使用 -
智博王锋:
好文章是要顶的!
Android中LayoutInflater的使用 -
云南白药:
...
Android中LayoutInflater的使用 -
万新one:
理解了许多。解释的不错。3Q.
Android中LayoutInflater的使用
import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import java.awt.Dimension; import java.awt.GridLayout; public class TableSortDemo extends JPanel { private static final long serialVersionUID = 1L; private boolean DEBUG = false; public TableSortDemo() { super(new GridLayout(1, 0)); JTable table = new JTable(new MyTableModel()); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true); table.setAutoCreateRowSorter(true); //这句话是重点 //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); } class MyTableModel extends AbstractTableModel { private String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; private Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) }, { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) }, { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) }, { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) }, { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) }, }; public int getColumnCount() { return columnNames.length; } public int getRowCount() { return data.length; } public String getColumnName(int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { return data[row][col]; } /* * * JTable uses this method to determine the default renderer/ * editor for each cell. If we didn't implement this method, * then the * last column would contain text ("true"/"false"), * rather than a check box. */ public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } /* * Don't need to implement this method unless your table's * editable. */ public boolean isCellEditable(int row, int col) { //Note that the data/cell address is constant, //no matter where the cell appears onscreen. if (col < 2) { return false; } else { return true; } } /* * Don't need to implement this method unless your table's * data can change. */ public void setValueAt(Object value, int row, int col) { if (DEBUG) { System.out.println("Setting value at " + row + "," + col + " to " + value + " (an instance of " + value.getClass() + ")"); } data[row][col] = value; // Normally, one should call fireTableCellUpdated() when // a value is changed. However, doing so in this demo // causes a problem with TableSorter. The tableChanged() // call on TableSorter that results from calling // fireTableCellUpdated() causes the indices to be regenerated // when they shouldn't be. Ideally, TableSorter should be // given a more intelligent tableChanged() implementation, // and then the following line can be uncommented. // fireTableCellUpdated(row, col); if (DEBUG) { System.out.println("New value of data:"); printDebugData(); } } private void printDebugData() { int numRows = getRowCount(); int numCols = getColumnCount(); for (int i = 0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j = 0; j < numCols; j++) { System.out.print(" " + data[i][j]); } System.out.println(); } System.out.println("--------------------------"); } } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("TableSortDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. TableSortDemo newContentPane = new TableSortDemo(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
发表评论
-
Swing中引入Android的NinePatch技术,让Swing拥有Android的外观定制能力
2012-09-21 09:22 1591【摘要】 本文诣在 ... -
JavaSwing实现支持合并拆分的JTable
2010-12-16 15:39 1945GridBagModel:抽象模型接口。该接口用于描述表格中单 ... -
JTable小例子,表格中使用JComboBox下拉按钮
2010-12-16 15:21 5397import java.awt.BorderLayout; ... -
配合滚动面板实现JTable上下翻页的效果
2010-12-16 14:26 3379import java.awt.BorderLayout; ... -
JScrollBar简单演示例子
2010-12-06 19:28 6585import java.awt.*; import java ... -
重写JSplitPane的BasicSplitPaneUI
2010-09-18 13:39 1544import java.awt.Color; import ... -
Swing窗口初始最大化的方法
2010-08-20 11:09 78491.设置窗口最大(伪最大化) JFrame frame =n ... -
Tree目录实现拖拽功能演示实例(DragAndDrop)
2010-08-10 16:49 1769import java.awt.BorderLayout; ... -
设置JTextPane指定内容的颜色
2010-05-21 14:29 1328package Assis; import java.a ... -
ScaleImageDemo图像缩小与放大演示
2010-05-12 14:59 2074package Assis; import java.a ... -
TreesDemo
2010-05-04 11:19 1053import java.awt.*; import java ... -
TableDemo
2010-05-04 11:17 1167import javax.swing.JTable; imp ... -
分割面板演示JSplitPaneDemo
2010-05-04 11:12 1353//Java Swing 带分隔条的面板代码 impor ... -
StylesExample8
2010-04-08 12:55 1168import javax.swing.*; import j ... -
StylesExample7
2010-04-08 12:54 967import javax.swing.*; import j ... -
StylesExample6
2010-04-08 12:52 1036import javax.swing.*; import j ... -
StylesExample5
2010-04-08 12:51 972import javax.swing.*; import j ... -
StylesExample4
2010-04-08 12:50 1073import javax.swing.*; import j ... -
StylesExample3
2010-04-08 12:50 968import javax.swing.*; import j ... -
StylesExample2
2010-04-08 12:49 1021import javax.swing.*; import j ...
相关推荐
NULL 博文链接:https://javapub.iteye.com/blog/783343
JTable表头合并, 很方便使用,swing的控件,下载下来,直接导入工程就可以使用了,接口封装的很好。想要什么样的表头都可以满足你
复杂JTable(复杂表头、跨行列表体)
复杂JTable-跨列表头, JTable表头合并,已经测试Ok,希望对你有用
jtable swing jtableheader netbeans 复杂表头 表头合并 使用netbeans打开后可以打开JFrame
jtable多级表头的实现,实现行表头和列表头的重叠
一个用鼠标点击JTable表头可以排序指定列的Java源代码.
Jtable表格排序,这两天公司让做一个Jtable表格的排序,首先按A列排序,在A列相等时按B列排序,B列相等时按C列排序,ABC三列可以任意指定,最多分三列,这样的一个需求。
JTable动态刷新数据JTable动态刷新数据JTable动态刷新数据JTable动态刷新数据
一个JTable里添加CheckBox的完整例子,包括表头的JCheckBox全选联动
JTable实现下拉动态加载数据,滑动动态加载数据,纯原生态java。
jtable 2 行表头显示功能 TableHeaderUI SimpleHashMap NewJFrame
使用JTable显示数据查询的数据集 包含数据库连接
主要介绍了Java Swing实现JTable检测单元格数据变更事件的方法,结合完整实例形式分析了Swing实现JTable检测单元格数据变更事件过程中出现的问题与相关解决方法,需要的朋友可以参考下
JTable排序
JTable数据模型设置与数据库综合应用,该文档使用的是sql server 2000 作为数据库服务器来实现的,简单说明了Jtable 数据模型的使用方法,以及数据库操作的基本写法。
介绍了jtable中加入复选的难点的俩个例子,方便大家更好的学习.
JTable的自动换行。挺好用的。里面还可以设置字体大小。分享一下。