Hello everyone I am new to blackberry and I want a textfield that scroll it's text i.e greater than the preferred width horizontally , also able to show label out side the text draw area ( e.g. on the left side). Please help me.
views:
622answers:
1
+3
A:
This may be achieved by combining non-scrolling and scrolling HorizontalFieldManagers.
Try this code:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
editHolder.add(new TextField(TextField.NO_NEWLINE));
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Setting default text code:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField(TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
// set some text then
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
textField.setText(text);
}
}
And something which basically works on 4.6/4.7:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("",text,1024,TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Border for Manager
Border border = BorderFactory.createSimpleBorder(new XYEdges(4,4,4,4));
fieldHolder.setBorder(border);
Fixed size Manager
class SizedHFM extends HorizontalFieldManager {
int mWidth = 0;
public SizedHFM(int width) {
super(NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
mWidth = width;
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mWidth, maxHeight);
setExtent(mWidth, getPreferredHeight());
}
}
Sample of use:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"
+ " adipiscing elit, sed diam nonummy nibh euismod tincidunt"
+ " ut laoreet dolore magna aliquam erat volutpat.";
SizedHFM fieldHolder = new SizedHFM(200);
Border border = BorderFactory
.createSimpleBorder(new XYEdges(4, 4, 4, 4));
fieldHolder.setBorder(border);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("", text, 1024,
TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Max Gontar
2010-03-30 07:23:39
Thanks Max for your quick reply but here I am not able to find the TextField constructor with four parameters in rim package.
Sachin
2010-03-30 07:28:59
Try to use import net.rim.device.api.ui.component.TextField; (for 4.6 and >)
Max Gontar
2010-03-30 07:29:33
for 4.5 and < see code update
Max Gontar
2010-03-30 07:34:12
even better without useless stuff...
Max Gontar
2010-03-30 07:34:36
I have tried with it but TextField constructor is either empty or taking only style. And I am using JDE 5.0.0 and api version is 4.7
Sachin
2010-03-30 07:35:20
that is strange. have you tried to compile it regarding what auto-complete says?
Max Gontar
2010-03-30 07:45:57
Thank u so much max now it is working properly but what if I want to set it's width and draw a rectangle around it so it will look like textfields in other languages.
Sachin
2010-03-30 07:48:59
See update. You really should read all of this: http://stackoverflow.com/questions/1445953/blackberry-user-interface-design-customizable-ui your answer is partially answered in other posts here. I just have occasion to answer it but in the future do some search before asking ;)
Max Gontar
2010-03-30 08:08:51
thanks max for your valuable suggestions and help provided by you
Sachin
2010-03-30 08:26:11
You're welcome! If this answer was the best one, please accept it (click check mark on the left side near answer)
Max Gontar
2010-03-30 08:38:56