Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
dankolix
Posts: 100
Registered: ‎06-21-2010
My Device: Not Specified

Re: Probably the simplest question ever

once again apologies for the newbieness!

 

I have just read on anonymous class and i inderstand a bit better what you were getting at !

 

Am currently tryin it out. Would let you know how i fare.

 

Thanks for the help again!

 

Dan

Please use plain text.
Developer
dankolix
Posts: 100
Registered: ‎06-21-2010
My Device: Not Specified

Re: Probably the simplest question ever

I also dont have any class called OneLineTextField

Please use plain text.
Developer
dankolix
Posts: 100
Registered: ‎06-21-2010
My Device: Not Specified

Re: Probably the simplest question ever

found this

 

OneLineTextField

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Probably the simplest question ever

Yes, that's one of the articles I recommended in my first post in this thread.

 

This code goes instead of the one you showed last - with all those ChatButtons and stuff.  I didn't do anything special, just quickly tested and illustrated to you that it works as it should.  Change the code as you see fit.

 

I've also shown how you can change colors in your chat window - use your own instead of CYAN and VIOLET.

 

Please understand that no one here is going to write the code fully for you - we show some snippets with ideas which you then customize to your needs.

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
titakalpesh
Posts: 203
Registered: ‎07-30-2009
My Device: Bold(9780),Curve(8520)
My Carrier: Vodafone

Re: Probably the simplest question ever

thanks

Please use plain text.
Regular Contributor
abhishek_puppalwar
Posts: 69
Registered: ‎01-17-2010
My Device: 9700 Bold
My Carrier: Airtel

Re: Probably the simplest question ever

[ Edited ]

You can use TextBox !!!!

There's class in BlackBerry API named TextBox which works as good as TextArea in JAVA

AbhishekPXP
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Probably the simplest question ever

TextBox is a J2ME UI Control, you can't use it in a RIMLet. 

Please use plain text.
Developer
dankolix
Posts: 100
Registered: ‎06-21-2010
My Device: Not Specified

Re: Probably the simplest question ever

i second peter,

 

 

Was just about to say the same thing!

Please use plain text.
Developer
dankolix
Posts: 100
Registered: ‎06-21-2010
My Device: Not Specified

Re: Probably the simplest question ever

Thanks Arkadyz for your continuous help.

 

I very much appreciate it.

 

I have been able to get everything showing on the screen!

 

the only (and major) problem is the fact that the TextBoxField is till not visible on the screen. Everything else seems fine.

 

 

Here is the TextboxField:

 

public class TextBoxField extends Manager{
	private int width;
	private int height;
	
	private VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR |USE_ALL_HEIGHT|USE_ALL_WIDTH);
	private EditField editField = new EditField ("Chat Window","New editField ", EditField.DEFAULT_MAXCHARS, FOCUSABLE);
	
	TextBoxField (int width, int height, long style){
		//super(style | NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
		super(style | VERTICAL_SCROLL | HORIZONTAL_SCROLL);
		this.width = width;
		this.height = height;
		
		add(vfm);
		vfm.add(editField);
		
	}
	
	TextBoxField(int width, int height) {
		this(width, height, 0L);
	}

	public String getText(){
		return editField.getText();
	}
	
	public void setText (String s){
		editField.setText(s);
	}
	
	public void append (String s){
//		editField.setText(editField.getText()+s);
		String newText = editField.getText() + s;
		editField.setText(newText);
		editField.setCursorPosition(newText.length());
		UiApplication.getUiApplication().invokeLater(new Runnable() {
			public void run() {
				vfm.setVerticalScroll(Math.max(0, vfm.getVirtualHeight() - vfm.getVisibleHeight()));
			}
		});

	}
	
	public int getPreferredWidth(){
		return width;
	}
	
	public int getPreferredHeight(){
		return height;
	}
	
	protected void sublayout(int width, int height) {
		if(this.width == 0){
			this.width = width;
		}
		
		if(this.height == 0){
			this.height = height;
		}
		
		int actWidth = Math.min(this.width, width);
		int actHeight = Math.min(this.height, height);
		layoutChild(vfm, actWidth-2, actHeight-2); //-2 is used to make space for the text area borders
		setPositionChild(vfm, 1, 1);
		
	}
	
	protected void paint(Graphics g){
		super.paint(g);
		int prevColor = g.getColor();
		g.setColor(Color.BLACK);
		g.drawRect(0, 0, getWidth(), getHeight()); //this draws the rectangular border needed for the chat area
		g.setColor(prevColor);
	}
	
	protected void paintBackground(Graphics g){
		g.setBackgroundColor(Color.RED); //
	    g.clear();

	}

}

 

 

 

 

And Here is the anonymous extension:

 

 

TextBoxField chatBox = new TextBoxField(100, 100, TextBoxField.READONLY | TextBoxField.FOCUSABLE | TextBoxField.NO_SCROLL_RESET) {
		protected void paintBackground(Graphics g) {
			int prevBg = g.getBackgroundColor();
			g.setBackgroundColor(Color.CYAN);
			g.clear();
			g.setBackgroundColor(prevBg);
		}
		
		protected void paint(Graphics g) {
			int prevColor = g.getColor();
			g.setColor(Color.VIOLET);
			super.paint(g);
			g.setColor(prevColor);
		}

 

I enclosed everything in a class called WowApp. its constructor looks like this

 

 

 

public WowApp (){
		horizonMan.add(sendButton);
		horizonMan.add(quitButton);
		vertMan.add(horizonMan);
		vertMan.add(new SeparatorField());
		vertMan.add(chatBox);
		chatScr.add(verticalMan);
		chatScr.add(new SeparatorField());
         	chatScr.add(messageEntry);
    	
    	pushScreen(chatScr);
	}

 

 

 

I need your help!

 

Thanks,

 

Dan

 

 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Probably the simplest question ever

You forgot

 

setExtent(actWidth, actHeight);

 as the last line in your TextBoxField sublayout.  Therefore its dimensions are (0, 0) and so it won't show on the screen.

Also, remove 

super(style | VERTICAL_SCROLL | HORIZONTAL_SCROLL);

and restore the commented out NO_... | NO_... version.  You have vfm for scrolling!

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.