0

I use LWUIT 1.4

1) In my Form there is a Container based on a BoxLayout ( Y axis ) , there are two Label's added to this container , and I want to create a titled Border to be placed into the container so it surrounds the two labels. I know to create a Border , but I do not know how to set a title to the Border with LWUIT 1.4 ! So how to set a title to a Border with LWUIT 1.4 ?

2) In my Form there is a Table based on the DefaultTableModel class whose getValueAt method is implemented with an enumeration of a recordstore , and I want that the rows of the Table are colored according to the index of the row : for example when the row index is odd then its background color should be white , and if the row index is pair then its background color should be gray. How to achieve that ?

3) Why do not the TableLayout.Constraint methods work ? I want to make two columns of a Table to have equal size , that is 50% of the Table total width for each column , but when I run the application then the first column is not equally sized with the second column when its data are not long enough ! So how to make the columns equally sized ?

Thank you very much indeed

bharath
  • 14,283
  • 16
  • 57
  • 95

2 Answers2

1

1) There is a titled border in the trunk but I think it was added in 1.4. You can draw something like this by overriding the Container paintBorder method (notice you will need sufficient component padding for the border to appear properly. This is the code from the SVN version, should work with very little changes (just change c to this):

Font f=c.getStyle().getFont();
int titleW=f.stringWidth(borderTitle);
int topPad=c.getStyle().getPadding(Component.TOP);
int topY=y+(topPad-thickness)/2;
if (c.isRTL()) {
    g.fillRect(x+width-TITLE_MARGIN, topY, TITLE_MARGIN , thickness); //top (segment before the title)
    g.fillRect(x, topY, width-(TITLE_MARGIN +titleW+TITLE_SPACE*2), thickness); //top (segment after the title)
    g.drawString(borderTitle, x+width-(TITLE_MARGIN +titleW+TITLE_SPACE), y+(topPad-f.getHeight())/2);
} else {
    g.fillRect(x, topY, TITLE_MARGIN , thickness); //top (segment before the title)
    g.fillRect(x+TITLE_MARGIN +titleW+TITLE_SPACE*2, topY, width-(TITLE_MARGIN +titleW+TITLE_SPACE*2), thickness); //top (segment after the title)
    g.drawString(borderTitle, x+TITLE_MARGIN+TITLE_SPACE, y+(topPad-f.getHeight())/2);
}

g.fillRect(x, y+height-thickness, width, thickness); //bottom
g.fillRect(x, topY, thickness, height); //left
g.fillRect(x+width-thickness, topY, thickness, height); //right

2) Derive table and override the method:

protected Component createCell(Object value, int row, int column, boolean editable)

call super.createCell() and set the UIID of the returned value to "OddRow","EvenRow" appropriately. Style in the resource editor or theme to anything you like.

3) I'm not aware of such an issue. If this happens on the current SVN you should file an issue in the projects issue tracker.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Can you explain clearly about the setUIID because I do not understand what you mean exactly after saying about setting the UIID to oddrow , evenrow , and the resource editor . –  May 25 '11 at 06:11
  • cmp.setUIID("OddRow"). This will mean that when you open a theme in the LWUIT resource editor you can assign a background color to the style OddRow.bgColor and it will apply only to the odd row. There are lots of explanations here http://lwuit.blogspot.com/search?q=resource+editor+tutorial – Shai Almog May 25 '11 at 10:27
  • Why there is a white rectangle painted when I click on a cell in the Table ? How to make this white rectangle disappear ? –  May 25 '11 at 12:22
  • You need to define the selected version of the style as well. – Shai Almog May 25 '11 at 18:31
1

I downloaded the latest Resource Editor from your blog site , and I defined the background and border "selected" versions of the component TableCell , but the extra-rectangle is always shown in runtime when I click on a last column table cell ! I tried to call tableName.repaint() in the component focusGained() implemented method , because I registered it to a focuslistener , but the rectangle does not disappear. I created a Dialog to show the selected row number and when the Dialog is shown when I click the third softbutton then the rectangle disappeared !!! Perhaps the focus is lost from the table cell !! And whenever I fire then I got the same row number as before ; so there is no row number error. So what code should I write , or what property should I edit in the Editor to get the same effect as of displaying the Dialog to make the rectangle disappear ?

bharath
  • 14,283
  • 16
  • 57
  • 95
  • I created a Theme with the latest Editor , and I set styles for the components oddRows and evenRows , for the unselected and selected tab pages . In my code in the createCell table method implementation I get the component style through comp.getUnselectedStyle and comp.getSelectedStyle and then I set these styles to the comp unselected and selected style. But in runtime it is only when I click the cell then it is painted ! So how to make the cells painted even if I do not click them ? –  May 26 '11 at 16:13