views:

360

answers:

2

I have a screen with two RadioButtonField objects. By default, the first RadioButtonField shows a rectangle around it to show its selected, and the rectangle moves if you change the selection to the other RadioButtonField or other buttons and textboxes on the page. What I would like to know is...is there a way to hide this border that shows the selection/border?

+1  A: 

You will need to override the drawFocus method of the object, by extending it.

Michael B.
Already tried that, and did not call super.drawFocus but it didn't remove the border for me.
Jessica
Ahh, I think I see why, from Max's answer that your solution isn't working for me. I am trying to compile against 4.7 extending drawFocus is only the solution for 4.6 and below. I probably should have mentioned my JDE version in my post!
Jessica
A: 

if you in 4.6 and higher, try to setBorder() without edges:

alt text

class Scr extends MainScreen {  
    EditField editField = new EditField("edit field", "text");
    RadioButtonGroup rbGroup = new RadioButtonGroup();
    RadioButtonField rbField = new RadioButtonField("First field");
    RadioButtonField rbField2 = new RadioButtonField("Second field");
    ButtonField buttonField = new ButtonField("button");
    Border invisibleBorder = 
        BorderFactory.createSimpleBorder(new XYEdges(0,0,0,0));     
    public Scr() {
        add(editField);
        rbGroup.add(rbField);
        rbGroup.add(rbField2);
        add(rbField);
        add(rbField2);      
        add(buttonField);       
        editField.setBorder(invisibleBorder);
        rbField.setBorder(invisibleBorder);
        rbField2.setBorder(invisibleBorder);        
        buttonField.setBorder(invisibleBorder);             
    }
}

If you in 4.5 and lower, try to override drawFocus() and leave it empty:

alt text

class Scr extends MainScreen {
    EditField editField = new EditField("edit field", "text") {
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    };
    RadioButtonGroup rbGroup = new RadioButtonGroup();
    RadioButtonField rbField = new RadioButtonField("First field") {
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    };
    RadioButtonField rbField2 = new RadioButtonField("Second field") {
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    };
    ButtonField buttonField = new ButtonField("button") {
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    };

    public Scr() {
        add(editField);
        rbGroup.add(rbField);
        rbGroup.add(rbField2);
        add(rbField);
        add(rbField2);
        add(buttonField);
    }
}
Max Gontar
Thanks! This helped me to discover that the border can also be changed only for a specific state, eg: rbField.setBorder(Field.VISUAL_STATE_FOCUS, invisibleBorder);
Jessica