Try using menuButton.getStyles().put("toolbar", true). That will
keep it from grabbing the focus when it's been clicked (though the
user will still be able to traverse to it), and it will only paint
its background and border when the mouse it over it.
-T
On Wed, Oct 21, 2009 at 9:03 AM, Alejandro Vilar
<alejandro.vi...@synacom.com.bo
<mailto:alejandro.vi...@synacom.com.bo>> wrote:
Basically what I want to do is an extension of TextInput
component with a Menubutton at the left side, I will use it for
some searches,
this MenuButton should let me choose some options for such
searches and I just want the focus event on the TextInput. Here
is my code:
Main class:
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.*;
public class Main extends Window implements Application {
public void startup(Display display, Map<String, String>
properties) throws Exception {
BoxPane boxPane = new BoxPane();
SearchTextInput input1 = new SearchTextInput();
SearchTextInput input2 = new SearchTextInput();
input2.setOptions(new String[]{"Option1", "Option2",
"Option3", "Option4"});
boxPane.add(input1);
boxPane.add(input2);
setContent(boxPane);
open(display);
}
public boolean shutdown(boolean optional) throws Exception {
close();
return false;
}
public void suspend() throws Exception {
}
public void resume() throws Exception {
}
public static void main(String[] args) {
DesktopApplicationContext.main(Main.class, args);
}
}
SearchTextInput class:
import org.apache.pivot.wtk.*;
import org.apache.pivot.wtk.content.ButtonData;
public class SearchTextInput extends BoxPane {
private TextInput textInput;
private MenuButton menuButton;
private ButtonData buttonData;
public SearchTextInput() {
super(Orientation.HORIZONTAL);
initComponents();
}
private void initComponents() {
textInput = new TextInput();
menuButton = new MenuButton();
menuButton.getStyles().put("focusable", false);//
<---problem here
buttonData = new ButtonData();
menuButton.setButtonData(buttonData);
getStyles().put("fill", true);
getStyles().put("spacing", 0);
getStyles().put("padding", new Insets(0, 0, 0, 0));
add(menuButton);
add(textInput);
}
public void setOptions(String[] options) {
Menu menu = menuButton.getMenu();
if (menu == null) {
menu = new Menu();
menuButton.setMenu(menu);
}
Menu.Section section = new Menu.Section();
Menu.Item item;
for (int i = 0; i < options.length; i++) {
item = new Menu.Item(new ButtonData(options[i]));
section.add(item);
}
menu.getSections().add(section);
}
}
Alejandro
Greg Brown escribió:
The styles supported by a component are defined by the
JavaBean properties of its skin class. For menu buttons, this
is an instance of
org.apache.pivot.wtk.skin.terra.TerraMenuButtonSkin by
default. TerraMenuButtonSkin doesn't define "focusable" or
"opaque" properties:
http://incubator.apache.org/pivot/1.3/docs/api/org/apache/pivot/wtk/skin/terra/TerraMenuButtonSkin.html
However, if you can describe more specifically what you are
trying to do, maybe we can help you find another way to
accomplish it.
Greg
On Oct 21, 2009, at 8:22 AM, Alejandro Vilar wrote:
Hi, I'm having some problems with MenuButton styles,
particularly with focusable and opaque,
I can't assign those values at runtime, for example:
Code:
public static void main(String[] args) {
MenuButton menuButton = new MenuButton();
menuButton.getStyles().put("focusable",
Boolean.FALSE); // doesn't work
menuButton.getStyles().put("opaque", Boolean.FALSE);
// doesn't work
menuButton.getStyles().put("color", Color.BLACK); //
it works
}
Console output:
"focusable" is not a valid style for
org.apache.pivot.wtk.MenuButton
"opaque" is not a valid style for
org.apache.pivot.wtk.MenuButton
(Seen in pivot 1.3/1.4)
Thanks in advance