Javafx Create custom multilabel button - javafx

How can I create a custom button in javafx. The button must have 3 label. An Upper Label a center LAbel and a lower label

Button button = new Button();
VBox threeLabels = new VBox();
threeLabels.setAlignment(Pos.CENTER);
threeLabels.getChildren.setAll(
new Label("upper"),
new Label("center"),
new Label("lower")
);
button.setGraphic(threeLabels);

Related

How to change contextMenu default mouse button?

I have a contextMenu and I added it to a button. I want the contextMenu to be displayed when I left-click(PRIMARY) on the button. How can I do this? Because by default just right-clicking does this.
I tried this way but it did not work
Button sortBy = new Button();
ContextMenu sortByMenu = new ContextMenu();
sortByMenu.addEventFilter(MouseEvent.MOUSE_PRESSED, ev -> {
if (ev.getButton() == MouseButton.PRIMARY) {
//does not do anything
}
});
sortBy.setContextMenu(sortByMenu);
MenuButton
MenuButton is a button which, when clicked or pressed, will show a ContextMenu.
Example code from the javadoc:
MenuButton m = new MenuButton(
"Eats"
);
m.getItems().addAll(
new MenuItem("Burger"),
new MenuItem("Hot Dog")
);
ChoiceBox
You could also consider a ChoiceBox, depending on what you are trying to do.
The ChoiceBox is used for presenting the user with a relatively small set of predefined choices from which they may choose.
ChoiceBox<String> cb = new ChoiceBox<>();
cb.getItems().addAll(
"item1",
"item2",
"item3"
);
To select a sortBy sorting field from a list of choices, a ChoiceBox would probably be a good fit.

JFX TableMenu context menu label empty

I wanted to add textfields to individual columns to allow individual column filtering. But after applying the following code, the table menu button on the top right corner when clicked, only displays 4 ticks(I have 4 columns), the label is missing. I assume this is because the header now is no longer just a label, but label with textfields. Anyone have a solution to this?
TextField headerTextField = new TextField();
Label label = new Label("First Name");
VBox headerGraphic = new VBox();
headerGraphic.setAlignment(Pos.CENTER);
headerGraphic.getChildren().addAll(label, headerTextField);
TableColumn<Person, String> firstNameCol = new
TableColumn<>();
firstNameCol.setGraphic(headerGraphic);

how to have a running program add tab panes javafx

Hello this is my question, In order to let a user add tabs with a new button would i need to create a whole new border panes and tab panes for this to work?
No you don't need if you have already created tabPane previously.
Button btn = new Button("add new tab");
btn.setOnAction( (e) -> {
tabPane.getTabs.add(new Tab("new tab"), new VBox(new Label(Content)) );
});

JavaFX put RadioButtons into GridPane

I have the following piece of code:
GridPane gp = new GridPane();
// filling GridPane with other nodes...
RadioButton maschio = new RadioButton("M");
RadioButton femmina = new RadioButton("F");
final ToggleGroup tg = new ToggleGroup();
maschio.setToggleGroup(tg);
femmina.setToggleGroup(tg);
gp.add(tg, 1, 3);
I got an error on the last line saying: ToggleGroup cannot be converted to Node.
What can I do? I also tried with Vbox, Hbox but it didn't work.
Tried to Google but didn't find the solution. Any suggestions?
ToggleGroup tg = new ToggleGroup();
RadioButton male = new RadioButton("Male");
male.setToggleGroup(tg);
RadioButton female = new RadioButton("Female");
female.setToggleGroup(tg);
HBox box = new HBox(20, male,female);
gp.add(box,1,3);
Toggle a control that can be toggled between selected and non-selected states. In addition, a Toggle can be assigned a ToggleGroup, which manages all assigned Toggles such that only a single Toggle within the ToggleGroup may be selected at any one time.
I found the following solution:
ToggleButton maschio = new RadioButton("M");
ToggleButton femmina = new RadioButton("F");
final ToggleGroup tg = new ToggleGroup();
HBox rbContainer = new HBox(maschio, femmina);
maschio.setToggleGroup(tg);
femmina.setToggleGroup(tg);
gp.add(rbContainer, 1, 3);
Is it ok? or you have better solutions?

how to position a button in HBox - JAVAFx

I am new to JAVAfx, i trying to code a web browser. The problem i am facing is :- i want to place the button present on the Bottom left of the screen to the bottom right.
I am trying this code but it is not working. Somebody please help
Button Developer = new Button();
Developer.setAlignment(Pos.BOTTOM_RIGHT);
here is the screenshot: http://i.stack.imgur.com/4RTpr.png
Thanks
You should be able to set the alignment on the HBox instead of the Button itself.
Button developer = new Button();
HBox hbox = new HBox();
hbox.setAlignment(Pos.BOTTOM_RIGHT);
hbox.getChildren().add(developer);

Resources