is possible increase the size of the buttons in dialog.
I need to be bigger.
Thanks
You can achieve it by accessing the ButtonBar of the dialog you created and then customize the buttons in it.
First get the ButtonBar instance:
ButtonBar buttonBar = (ButtonBar)yourDialogInstance.getDialogPane().lookup(".button-bar");
Then get all buttons applied to the dialog pane and set the style for them via a string containing css. For example:
buttonBar.getButtons().forEach(b->b.setStyle("-fx-font-size: 18px;"));
A lot more detail: Customizing Dialogs
Related
I have a JDialog that contains a large number of options and it was all working fine, however I have changed it so that by default some options are non visible until the unless the user clicks on the Show Advanced button.
When they they do this the options are displayed but because the dialog is not tall enough since it was sized based on those options being hidden a vertical scrollbar is added.
I want the dialog to be sized so large enough for when the advanced options are enabled. I have attempted this by creating the dialog with the advanced option displayed, calling pack() to fit based on advanced options being visible
this.pack();
showAdvancedAction.actionPerformed(null);
and then afterwards calling method to make advanced options invisble.
But still when diplayed the dialog is only large enough for when the options are not shown so when click on Show Advanced the dialog adds scroll bar again.
How can I resolve this.
this.pack();
showAdvancedAction.actionPerformed(null);
You have the order reversed. You need to pack the frame AFTER the components have been made visible.
showAdvancedAction.actionPerformed(null);
this.pack();
In java swing you can add buttons or components over the panel. but when you try to resize these then you need to use Grid Layout/ GridLayout class. Try using Grid Layouts and arrange your controls by providing X, Y co-ordinate values. It will definitely work.
I've created a dialog in the designer.
What is the best way to add a close icon to the dialog (for example in the title area, top left)?
I've tried adding a command in the designer, but could not get it to work: it didn't show up.
Could I access the dialog programmatically and add a close icon?
Normally the title area is hidden so there isn't much I can do there.
Commands in Dialog are a bit of a special case where they act like buttons in some cases but never appear in the title since this doesn't make as much sense in a dialog.
If you are using the GUI builder the simplest workaround for something like this is to not set a title and set the layout of the Dialog to BorderLayout.
In the center area just place your UI as usual. In the north do something like this:
Button closeButton = new Button(...);
Container myTitle = new Container(new BorderLayout());
myTitle.setUIID("DialogTitleArea");
myTitle.add(BorderLayout.CENTER, new Label("My Title", "DialogTitle")).
.add(BorderLayout.EAST, closeButton);
dlg.add(BorderLayout.NORTH, myTitle);
When I call setItems(String[]) the combo box will become wider to fit the length of the new items.
How to make it not resizable no matter how wide the new items are?
I've tried it with ControlListener. I saved the initial size of the combo and set it each time the controlResized() was called. As the result the combo width remains constant but the rest of the UI looks ugly when I resize it. It is a wizard. I'm using GridLayout
If you are using GridLayout for your layout you can specify a widthHint in the layout data for the combo.
GridData data = new GridData(....);
data.widthHint = 100;
combo.setLayoutData(data);
If this is in a dialog you can use convertWidthInCharsToPixels(chars) to specify a width in characters rather than pixel. Dialog also has a static version of this method you can use outside of a dialog.
The buttons in my JavaFX application look very nice on all operating systems with default font settings.
Howerver, if I increase the scale of text in the windows control panel,
the text on the JavaFX buttons increases wheareas the button size stays the same.
Therefore I get a button with 3 letters and an ellipsis (...).
How can I achieve that control elements in javaFX scale according to the system font?
It depends of multiple things.
First the layout in wich are your button.
And if you set a hard size to your button.
verify that you don't set a size to your button. And the parent layout size to a size smaller than the button size.
And try to set your button size with button.setPrefWidth(Control.USE_COMPUTED_SIZE) if it's still not working your parent layout is probably the cause.
You should try to play a little with SceneBuilder for a better understanding of how layout works
Now I have a panel called panel1, and I would like to place a button on panel1, and set the position of the button as (30,30). How can I do this?
I tried this, but seems that it is not the right way:(
int x = panel1.getX();
int y = panel2.getY();
button.setLocation(x+30,y+30);
Thanks a lot, the layout manager seems to be a good choice, but here is my problem, I need to generate many buttons dynamically on the panel, and the button size is also different. So which layout manager shall I use? According to the tutorial, it seems that there is no such layout manager....A key problem is I don't want the buttons to look like they are organized in grid, for example, button1 at (20,20) size 15, and button 2 at (40,70) size 20, button 3 at (150,40) size 5.....
I want the buttons to be scattered in the panel.
It's tempting to use an absolute layout for this, but you'd have to figure out a way to keep the buttons from overlapping or even hiding each other. It may be worth Creating a Custom Layout Manager.
Use the form designer in NetBeans and you can place buttons at arbitrary locations relative to each other in a GUI interface. The builder uses the GroupLayout which you could do manually, but it's not recommended.