BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-07-2006, 09:19 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Sep 2006
Model: 8700c
Carrier: Cingular
Posts: 32
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Borders & BasicEditField?

Please Login to Remove!

I want to implement a numerical edit field, sort of in the style of a spreadsheet - fixed size with a border. What I've ended up doing is overriding BasicEditField and/or its manager and manually drawing lines around the edit fields or groups thereof (in a table layout). This approach is workable, but kludgy, and creates layout issues that make it more difficult than it should be.

Seems it would be much cleaner to use existing capability, if it's available: There's some sort of border functionality built in to the framework: found a class called XYEdges, which implements "padding, borders and margins", apparently used in conjuction with with XYRect. But no information ANYWHERE as to how to use it. Also, when you drill down into BasicEditFields' members in the debugger, there's an instance of a class "net.rim.device.interal.ui.Border".

So what's up with this native border attribute? How do I get at it and activate it? More to the point, where's the ^&#%@$@ documentation?!?! (Hasn't anyone written a 3rd-party book on the BB API?!?!).

Thanks for any info...
Offline  
Old 07-19-2007, 10:40 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I too need to put a border on either a BasicEditField, EditField, or AutoTextEditField, but I can't find a way to do it.

I agree with Kvon. Shouldn't this be really simple? Shouldn't it be something like:

EditField ef = new EditField();
ef.setBorder( whateverBorderStyle);

???

There's GOT to be a way to do it, right? Otherwise, how does anyone create Blackberry applications with nice-looking user interfaces?

Am I just taking the wrong approach? Is all that (border styles, font styles, colors, etc) controlled in the layout managers, or something else? I'm open to trying a different way, but I've just gotta have a better looking UI.

Any thoughts?

Much thanks,

Mike
Offline  
Old 07-19-2007, 11:24 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

create your own custom field, use the class used in this app for starters: Wikipedia Application for BlackBerry
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 07-19-2007, 11:24 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

One idea would be to implement the paint method of your custom field, draw a border by limiting the extent of the field and painting the rectangle, then limit the extent to be within that rectangle and super.paint() whatever field you've extended. I *think* that would work
Offline  
Old 07-19-2007, 08:30 PM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default EditField WITH A BORDER

Thank you very much for your help jfisher and bemshaswing!

With your help, I've been able to make a simple extension of the EditField class WITH A BORDER! I learned how to do this mostly from jfisher's code, which he generously shared on his website. (SEE URL IN jfisher's POST ABOVE) His example is much more comprehensive, but I've listed my code below in case it might be helpful to anyone. The actual class is 'MyEditField', but I included the other junk to show how to use it. Please let me know if anyone finds any problems with this code. (Written with JDE 4.1).

//---------------------------------------------
//---------------------------------------------
package com.vertsol.mike.testapp;

import net.rim.device.api.ui.*; //UiApplication
import net.rim.device.api.ui.container.*; //FullScreen
import net.rim.device.api.ui.component.*;

class TestApp extends UiApplication
{
//START
public static void main(String[] args)
{ TestApp ta = new TestApp();
ta.enterEventDispatcher();
}

//CONSTRUCTOR
TestApp()
{ MyFullScreen mfs = new MyFullScreen();
pushScreen(mfs);
}
}

class MyFullScreen extends FullScreen
{
MyFullScreen()
{ MyEditField txt1 = new MyEditField("Larry: ", "Let's see what happens when we add a whole bunch of text.");
MyEditField txt2 = new MyEditField("Moe: ", "Now, just a little text.");
MyEditField txt3 = new MyEditField("Curly: ", ""); //no starting text
add(txt1);
add( new LabelField("")); //Just for some breathing room between the EditFields
add(txt2);
add( new LabelField("")); //Just for some breathing room between the EditFields
add(txt3);
}
}

//--------------------------------------------------------------------------------------------------
//DESCRIPTION: An EditField with a border around the Text Part.
//
//REFERENCES:
//1) jfisher's website (see url in above post).
//2) Blackberry Application Developer Guide Volume 1 [Version 4.1.0 Service Pack 1] p.55 - 58.
//
//NOTES AND LIMITATIONS:
//1) This works only if the label part of the EditField can fit all on one row.
// I.e. The width of the label part must be less than the entire width.
//2) The text touches the border on multiple lines. Ugly, but I haven't figured a way around that.
// I tried messing with the graphics.drawText(),
// but I couldn't get it to wrap to multiple lines.
//--------------------------------------------------------------------------------------------------
class MyEditField extends EditField
{
MyEditField( String label, String text)
{ super( label, text);
}
public void paint(Graphics graphics)
{
super.paint(graphics);

int labelWidth = getFont().getAdvance(getLabel()) - 1; //Just the label width (not the text).
int textWidth = getFont().getAdvance(getText());
int entireWidth = getWidth() - 1;
int fontHeight = getFont().getHeight();
int entireHeight = getHeight() - 1;

//SINGLE ROW
if (labelWidth + textWidth < getWidth())
{
graphics.drawRect
( labelWidth,
0,
getWidth() - labelWidth,
getHeight()
);
}
//MULTI ROW
//If text is multiple rows, then make a "inverted Utah" shape.
//The missing chunk of "Utah" allows for the label.
else
{
graphics.drawLine( 0, fontHeight, labelWidth, fontHeight); //-
graphics.drawLine( labelWidth, fontHeight, labelWidth, 0); //|
graphics.drawLine( labelWidth, 0, entireWidth, 0); //--
graphics.drawLine( entireWidth, 0, entireWidth, entireHeight); //|||
graphics.drawLine( entireWidth, entireHeight, 0, entireHeight); //---
graphics.drawLine( 0, entireHeight, 0, fontHeight); //||
}
}
}

Last edited by bbCincinnati : 07-19-2007 at 08:33 PM. Reason: Clarification, and Grammar
Offline  
Old 07-20-2007, 10:06 AM   #6 (permalink)
New Member
 
Join Date: Jul 2007
Location: Atlanta, GA, USA
Model: 8100
PIN: N/A
Carrier: n/a
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Post Scrolling, FWIW

Quote:
Originally Posted by jfisher View Post
create your own custom field, use the class used in this app for starters: Wikipedia Application for BlackBerry
Jonathan, for what it's worth , you may have been able to achieve your desired scolling by dropping the editfield into a manager that has horizontal scrolling enabled.

When populating the screen's controls construct a new manager (e.g. HorizontalFieldManager) with style Manager.HORIZONTAL_SCROLL, then add your editField to the hm, which is added to the screen instead of the editfield.

However... your drawn box could be scrolled off-screen then, but the box rendering could be moved into a manager sub-class as well.
Offline  
Old 07-23-2007, 03:50 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you tried this without using the full screen width? i've not managed it in the past, if you set the limits for screen co-ordinates as well it gets even more complicated. if you can managed to get a center aligned field with internal text scrolling using the default ui elements it'd be good if you could post the source,
cheers, jon.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.