[TIP] Using ColorSchema for TableItem

There is custom component TableItem available in palette of NetBeans Mobility Pack. It was added in version 5.0 of the Mobility Pack. Later we discovered that the TableItem displays in black color only on some devices - e.g. BlackBerry. There are issues filled for those problems 79625, 80447.

The "all in black" problem is mostly caused by the wrong return values of getDisplay().getColor(Display.COLOR_\*);. It returns 0 for all the Display.COLOR_\* constants on BlackBerry.



This issue can be solved in Mobility Pack 5.5 (and later) with ColorSchema class. Look at the image on the right side. The table looks definitely better.
You can specify what ColorSchema should be used by your TableItem by calling method aTableItem.setColorSchema(ColorSchema schema);.


Example of ColorSchema Usage

I will define a ColorSchema first.
ColorSchema myOwnColorSchema = new ColorSchema() {
            
            public int WHITE = 0xffffff;
            public int BLACK = 0x000000;
            public Image getBackgroundImage() {
                return null; //there won't be any background image
            }
            public int getBackgroundImageAnchorPoint() {
                return 0; //there won't be any background image
            }
            public int getColor(int aColorSpecifier) {
                switch (aColorSpecifier) {
                    case Display.COLOR_BACKGROUND:
                    case Display.COLOR_HIGHLIGHTED_FOREGROUND:
                        return WHITE;
                    case Display.COLOR_HIGHLIGHTED_BACKGROUND:
                    case Display.COLOR_BORDER:
                    case Display.COLOR_HIGHLIGHTED_BORDER:
                    case Display.COLOR_FOREGROUND:
                        return BLACK;
                    default:
                        return BLACK;
                }
            }
            
            public boolean isBackgroundImageTiled() {
                return false;//there won't be any background image
            }
            public boolean isBackgroundTransparent() {
                return false;//there won't be any background image
            }
        };

The ColorSchema is abstract class therefore you have to implement its methods when you are creating it.

Then I'll use the color schema for my TableItem. It's highly recommended to access the components used in Visual Design by the getter methods(get_).
get_tableItem1().setColorSchema(myOwnColorSchema);


You can download sample project. It shows how to use the ColorSchema. It will display the settings of your device too.
Comments:

Hi, I would like to share that modifing the get_tableItem1() of HelloMidlet.java code as below works too : \*\*\*\*\*\*\*\*\*\*\*\* public org.netbeans.microedition.lcdui.TableItem get_tableItem1() { if (tableItem1 == null) { // Insert pre-init code here tableItem1 = new org.netbeans.microedition.lcdui.TableItem(getDisplay(), "tableItem1", get_simpleTableModel1()); // Insert post-init code here tableItem1.setColorSchema(new ColorSchema() { public Image getBackgroundImage() { return null; } public int getBackgroundImageAnchorPoint() { return 0; } public int getColor(int aColorSpecifier) { return Display.COLOR_FOREGROUND; } public boolean isBackgroundImageTiled() { return false; } public boolean isBackgroundTransparent() { return true; } }); } return tableItem1; } \*\*\*\*\*\*\*\*\*\*\*\*\*\*

Posted by Suyukti B N on March 29, 2007 at 03:17 AM CEST #

Hi~What if I want to have the different color of font in the different cell. Do you have any idea about that? Can I also do that by using ColorSchema?

Chuan

Posted by Chuan on January 24, 2008 at 07:50 AM CET #

the ColorSchema defines behavior for the whole table not for particular cell. However you can implement your own TableItem.

Posted by Lukas on January 24, 2008 at 08:25 AM CET #

Thanks Lukas - looks like they still havent resolved the issue in the latest release.

Your insight was very useful and saved me a lot of time debugging the TableItem.

Posted by Peter on April 04, 2008 at 09:04 PM CEST #

I've the same problem on blackberry and this code resolves this .Now I can see the grid. But another problem on blackberry is you can not move horizontally with that code. I think that blackberry could only move to focusable items. And also another problem I dont understand that with above code only first column is focusable.
Why not I focus on the second or other columns
on blackberry?
If we could, we 'll move horizontally, I thought.

Posted by Bertan on August 29, 2008 at 01:21 AM CEST #

Lukas,

Thanks for your help on this issue. Your article has given me some hope on cross-platform development.

> Why not I focus on the second or other columns on blackberry?
This is a bug with TableItem, its only coded to use the direction pad on a phone with a keypad. Here's my work-around:
http://fatbuttlarry.blogspot.com/2010/04/j2me-selectable-table-in-netbeans.html

-Tres

Posted by Tres Finocchiaro on April 03, 2010 at 12:42 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This is the main channel to share news, tips and other stuff related to my work. Sometimes you can find even personal stuff. Enjoy your reading...

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today
news
Blogroll

No bookmarks in folder

OldNews
MyTrash
NavBar
NetBeans
LinksToBeExpanded