在Eclipse RCP 设置表格的行高、背景颜色以及字体等等
2010-04-08 21:38
351 查看
基于RCP平台写程序的时候,经常遇到需要设置table行高的问题。Table和TableItem以及TableViewer类中都没有相应的方法可用。于是综合了一下网友的智慧,找到了几个设置表格控件行高的方法
第一种,通过设置指定height的Image来改变行高,代码演示如下:
不过就算我只在item1上setImage,item2和item3行高也会一起改变,没法单独指定某一行的高度。
第二种,是通过捕获SWT.MeasureItem事件来定制单元格的高度和宽度,具体内容可参看原文Custom Drawing Table and Tree Items,代码演示如下:
同样的,这个方法也不能为每一行指定不同的行高,在原文中也说了"All items in a table have the same height, so increasing the height of a cell will result in the height of all items in the table growing accordingly."。看来这一点在SWT中是做不到了。
至于设置背景颜色以及字体,如果是基于SWT的应用程序,可以直接调用table的相应方法来实现,如果使用的是JFace中的TableViewer,可以在LabelProvider 中实现ITableColorProvider、ITableFontProvider接口即可!!
第一种,通过设置指定height的Image来改变行高,代码演示如下:
Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 250); Table table = new Table(shell, SWT.NONE); table.setBounds(10, 10, 150, 200); table.setLinesVisible(true); int rowHeight =30; TableItem item1 =new TableItem(table, SWT.NONE); item1.setText("item 1"); TableItem item2 =new TableItem(table, SWT.NONE); item2.setText("item 2"); TableItem item3 =new TableItem(table, SWT.NONE); item3.setText("item 3"); Image image = new Image(display, 1, rowHeight); item1.setImage(image); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();
不过就算我只在item1上setImage,item2和item3行高也会一起改变,没法单独指定某一行的高度。
第二种,是通过捕获SWT.MeasureItem事件来定制单元格的高度和宽度,具体内容可参看原文Custom Drawing Table and Tree Items,代码演示如下:
Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 250); final Table table = new Table(shell, SWT.NONE); table.setBounds(10, 10, 150, 200); table.setLinesVisible(true); final int rowHeight =30; for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE).setText("item " + i); } table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { event.height =rowHeight; } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();
同样的,这个方法也不能为每一行指定不同的行高,在原文中也说了"All items in a table have the same height, so increasing the height of a cell will result in the height of all items in the table growing accordingly."。看来这一点在SWT中是做不到了。
至于设置背景颜色以及字体,如果是基于SWT的应用程序,可以直接调用table的相应方法来实现,如果使用的是JFace中的TableViewer,可以在LabelProvider 中实现ITableColorProvider、ITableFontProvider接口即可!!
相关文章推荐
- 在Eclipse RCP 设置表格的行高、背景颜色以及字体等等
- MFC中设置静态文本的字体颜色、背景透明以及解决字体重叠
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- PHPExcel-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- 设置表格的背景颜色和字体颜色
- ios自定义导航navigation,设置navigation的背景图,navigation左边按钮,以及navigation字体颜色
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- MFC中设置静态文本的字体颜色、背景透明以及解决字体重叠
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- MFC中设置静态文本的字体颜色、背景透明以及解决字体重叠
- PHPExcel-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- TextView设置超链接、背景颜色、字体颜色等等,Spannable的使用。
- MFC中设置静态文本的字体颜色、背景透明以及解决字体重叠
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
- android 动态java代码设置背景以及字体等颜色
- MFC中设置静态文本的字体颜色、背景透明以及解决字体重叠
- 快速设置UINavbar的属性包括背景 title的颜色字体以及改变返回键的图片
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)