I have been endeavoring to implement a JavaFX application using FXML which includes a toolbar in the bottom region of a BorderPane populated with four buttons displaying graphics only.
However, the buttons are displayed in gray outline only with no graphic content.
A simplified snippet of the FXML file is as follows:
<bottom>
<ToolBar fx:id="tbTextColor" >
<Button fx:id="btnRed" contentDisplay="GRAPHIC_ONLY">
<graphic>
<ImageView>
<image>
<Image url="#red.png"> </Image>
</image>
</ImageView>
</graphic>
</Button>
<!--more buttons-->
</ToolBar>
</bottom>
If anybody can inform me how to achieve the desired result, it will be much appreciated.
Thanks.
I'm trying to write a javafx application where the UI behaves similar to the phone dialer on a cell phone. There will be a layout with a few buttons at the top that change the contents of the area below them. I've defined the layout of the parts that change in FXML files and they all load and work fine.
My question is how do I define the "area" that changes in the main FXML and how do I swap in the new contents in the button event handler?
My main FXML layout looks like this:
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="CENTER" hgap="20" vgap="10"
fx:controller="application.Main" >
<Button text="Dialer" alignment="CENTER"
GridPane.columnIndex="0" GridPane.rowIndex="0"
onAction="#handleModeAction" />
<Button text="Log" alignment="CENTER"
GridPane.columnIndex="1" GridPane.rowIndex="0"
onAction="#handleModeAction" />
<Button text="Contacts" alignment="CENTER"
GridPane.columnIndex="2" GridPane.rowIndex="0"
onAction="#handleModeAction" />
<!--
What goes here??
-->
</GridPane>
I read through the previous posts that looked similar but none looks quite like I thought it worked.
Thanks for any pointers
dave
How to create a custom round button in fxml,I've tried this Code
<Button fx:id="button" layoutX="273.0"
layoutY="103.0" mnemonicParsing="false"
onAction="#next"
style="-fx-base:#b6e7c9;
-fx-font:12 papyrus;
-fx-border-radius:15px 50px 30px 40px ;
-fx-border:2px solid;"
textOverrun="CLIP">
</Button>
Maybe you should take a look of this 4 Using FXML to Create a User Interface
And this one maybe could help you :)
JavaFX - create custom button with image
I am having a weird problem with JavaFX and Font Awesome, which I'm having trouble pin-pointing the cause of. The problem is further complicated because I can't really share the code, and no matter how much I've tried to replicate the problem in a simpler case - I couldn't.
The problem is as follows - I have a TableView, in which every column has a Hyperlink as a graphic, with a Font Awesome glyph. This all works well, except for one stage - in this stage, the first time it is shown everything is fine, but the second time three of the columns' glyphs revert to squares. This is weird, as all columns use the same glyph of the same font.
Here are before and after pictures - notice the glyphs are all the same, but the left ones become squares:
The glyphs and font are set through FXML, and are the same for all columns:
<TableColumn fx:id="col1" prefWidth="83.0" text="Column 1"><graphic>
<Hyperlink onAction="#requestFilter" text="" visited="true">
<font>
<Font name="FontAwesome Regular" size="13.0" />
</font></Hyperlink>
</graphic>
</TableColumn>
<TableColumn fx:id="col2" prefWidth="138.0" text="Column 2"><graphic>
<Hyperlink onAction="#requestFilter" text="" visited="true">
<font>
<Font name="FontAwesome Regular" size="13.0" />
</font></Hyperlink>
</graphic>
</TableColumn>
<TableColumn fx:id="col3" prefWidth="59.0" text="Column 3"><graphic>
<Hyperlink onAction="#requestFilter" text="" visited="true">
<font>
<Font name="FontAwesome Regular" size="13.0" />
</font></Hyperlink>
</graphic>
</TableColumn>
<TableColumn fx:id="col4" prefWidth="103.0" text="Column 4"><graphic>
<Hyperlink onAction="#requestFilter" text="" visited="true">
<font>
<Font name="FontAwesome Regular" size="13.0" />
</font></Hyperlink>
</graphic>
</TableColumn>
Here the last two columns are the ones who lose their glyph (the scene is in right-to-left orientation).
Furthermore - it is always the last three columns that lose their glyph, that is - if on the first showing I reorder the column, the columns I leave last in the table (to the left, again - the scene is right-to-left) will lose their glyph the next time the stage is shown. Subsequent hiding/showing won't lost any more glyphs.
I show the stage with Stage#showAndWait, and I keep a reference to the stage, so it is only created once.
I realize it is hard to help when I can't share any code (client confidentiality), so what I'm asking is - where can I look to see what is happening? How come some instances of the same glyph disappear and others don't? Did anyone else encounter something like this? What was the underlying reason?
Edit: I have added debug prints of the hyperlinks' properties, and indeed with the second showing the font reverts to "System" for the last three columns. Looking for the source of the change, I have added a change listener, and put breakpoint inside it. The stack shows that the change happens inside applyCSS, after a lot of internal calls following showAndWait, non of them in my own code (i.e. - all in the JavaFX library code). It seems for some reason JavaFX decides to reset the font definition of some of the controls, although they are all defined exactly the same! This is corroborated by the fact that it doesn't matter which table-column it is, but where it is in the TableView.
So it seems like some erroneous JavaFX behavior is resetting the font to the default ("-fx-font") instead of the one defined on the node itself. Anyone know enough about the JavaFX CSS logic to help find the bug?
All hyperlinks have no custom styles or classes set, and only the 'visited' pseud-class set.
Edit 2: Adding a font name to the CSS fixes the issue. I would still love to find the source of the bug (which, I am certain, is in the JavaFX CSS handling), but it is too messy for me to go through it now. The CSS I use is:
.table-column .hyperlink {
-fx-font-family: "FontAwesome";
}
My bet that some code or css styling somewhere is changing Hyperlink font or style or css class. You can use some debugging. For example, you can add button near your TableView to print some debug information, something like this:
Button b = new Button("Debug");
b.setOnAction(e->{
TableView<?> tv = (TableView) scene.lookup("#tableView");
for(TableColumn<?,?> tc : tv.getColumns()) {
Hyperlink link = (Hyperlink)tc.getGraphic();
System.out.println("Column "+tc.getText());
System.out.println("link text: "+link.getText());
System.out.println("link Style: "+link.getStyle());
System.out.println("link CSS Classes: " + link.getStyleClass());
System.out.println("link CSS Pseudo Classes: " + link.getPseudoClassStates());
System.out.println("link Font: " + link.getFont());
}
});
Then click this button when table looks normal and save debug info somewhere. Click again when squares appear and compare the output with first one. Also inspect your css files and code that can access TableColumns, if any of those can affect Hyperlink styling.
EDIT
Well, it seems pretty strange to me, that JavaFX all by itself internal logic decided to recalculate and reapply css styles only for specific columns and not for the whole scene (EDIT: according to JavaFX CSS Reference it actually can reapply css only on specific branches in scene graph). I still think that the root cause somewhere in your styling or code. I doubt anyone could point you to a place to look at, as it seems very specific problem and, as you said, can't be reproduced in simple scenario. Maybe you perform some specific layouting logic, recreating/replacing table nodes or somthing similar, hard to say not seeing the code.
Anyway, if you just want to solve the problem, I would suggest to set hyperlink font style in css file, not in fxml. This way you ensure that even in case of css recalculation or any layout manipulations style will be the same. It would be the right way to do it anyway.
If you want to dig up the real cause of a problem, I afraid you have to spend some happy hours with your debugger:) I would start from searching the differences between normal column and column with broken font. Why do they treated in different ways?
I am having issues getting setCursor() to work properly in TextArea. I am not seeing any other search results at all for issues with this, and might be doing something silly because no one else has addressed this yet. I have tried different options, with no luck. Here are a few attempts below:
Coding this below makes it so only the outer edges are effected by the setCursor.
textArea.setCursor(Cursor.DEFAULT);
In FXML, I get the following if I add it in with Scene Builder.
<TextArea fx:id="textArea" prefHeight="458.0" prefWidth="766.0">
<font>
<Font name="System Bold" size="12.0" />
</font>
<cursor>
<Cursor fx:constant="DEFAULT" />
</cursor>
</TextArea>
It gives me an error, so I add the import...
<?import javafx.scene.Cursor?>
Then it gives me an error, saying "Instances of javafx.scene.Cursor cannot be created by FXML loader." with no hints provided.
I know for ComboBoxes, I have to do the following:
comboBox.getEditor().setCursor(Cursor.DEFAULT);
Is there some way I have to do this for TextArea to work as well?
Thanks!
Your FXML parsed just fine for me, though it didn't have the desired effect. I'm not sure why it gave you errors.
The reason it doesn't generate the desired cursor is that the Text node is placed as the content of a ScrollPane. The cursor is set by default on that Text node, so it isn't inherited if you set the cursor directly on the TextArea.
The easiest way to do this is to use an external CSS file:
.text-area .content {
-fx-cursor: DEFAULT ;
}