I'm developing app using javafx 2.0.
I want to place several tabs in a single row, maybe draw tab label multiline. How can I remove tab switcher?
Piece of my fxml with TabPane:
<TabPane layoutY="0.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
***
***
</tabs>
</TabPane>
Can anyone help me?
Upd.
javafx.runtime.version=8.0.60
javafx.runtime.build=b27
Related
How do I make changes to generated items using FXML?
When creating a JavaFX ToolBar, a nested HBox (or VBox) is generated automatically. For example, I would like to set the spacing of this generated HBox to 0.
<ToolBar fx:id="welcomeToolBar" prefHeight="50">
<items>
<Button fx:id="closeButton" prefHeight="50" prefWidth="100" onAction="#closeWindow" text="Close" />
<Button text="New Image" prefHeight="50" prefWidth="100" onAction="#newImage" styleClass="button-accent"/>
<Pane HBox.hgrow="ALWAYS"/>
<CheckBox text="Hide this window on application start"
fx:id="hideOnLoadCheckBox" onAction="#setVisibilityOnApplicationLoad"/>
</items>
</ToolBar>
Use the CSS property -fx-spacing (uses the <size> type). You can do this in a separate CSS file and link the file or do this directly in the FXML file using the style attribute.
Example FXML:
<ToolBar fx:id="welcomeToolBar" prefHeight="50" style="-fx-spacing: 0px;">
<!-- items -->
</ToolBar>
Example CSS:
.tool-bar {
-fx-spacing: 0px;
}
The reason this works is that the default skin of the ToolBar class exposes a StyleableProperty for spacing1. I found it in the "CSS Analyzer" of Scene Builder and the JavaFX 9 (and 8)2 source code (for some reason can't get Scenic View to run). I couldn't find any documentation on this property, however; even in the JavaFX CSS Reference Guide.
1. Another undocumented styleable property exposed by the default skin (at least in JavaFX 13) is -fx-alignment which accepts a javafx.geometry.Pos. These properties are applied to the HBox or VBox depending on if the toolbar's orientation is horizontal or vertical, respectively.
2. Still present in the JavaFX 13 source code.
I am writing a simulation software for my Masters and it consists on a "Graph container" where you can link nodes to generate equations according to what I link. These equations will, then, enable me to simulate my model. I am using Java 8 and JavaFX for that, with Scene Builder and FXML.
Searching on the web, I found the Graph-Editor (https://github.com/tesis-dynaware/graph-editor), which will help me a lot with what I need. Following the Tutorial on the project's site, I could reproduce it and it is running. But on my software I do not need to create a new window as the tutorial does to use the graphs - instead, I want to have a TabPane that enables me to create as many models as I need, like a text editor, and if I want I can save it on XML, etc...
My problem is: I tried to put the graphs from the tutorial inside the Tab they do on the tutorial (with the getView method) and it is not working. I tried it in two different ways, which result in an empty Tab, with no nodes and no error on the console.
First try
I tried putting into a Pane and set the GraphEditor inside the Pane.
My java code:
private GraphEditor graphEditor = new DefaultGraphEditor();
#FXML
private Pane graphEditorPane;
#FXML
public void initialize(){
graphEditorPane = new Pane(graphEditor.getView());
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
addNodes(model);
}
My FXML code:
<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Modelo 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<Pane fx:id="graphEditorPane" prefHeight="571.0" prefWidth="1000.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
Second way
I have seen their demo source code and what I understood was that they created an instance of their GraphEditorContainer object and then their FXML file has that GraphEditorContainer, but mine doesn't work that way. Maybe I got what they did wrong (I am a beginner in Java and JavaFX).
My java code:
private GraphEditor graphEditor = new DefaultGraphEditor();
#FXML
private GraphEditorContainer graphEditorContainer;
#FXML
public void initialize(){
graphEditorContainer = new GraphEditorContainer();
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
graphEditorContainer.setGraphEditor(graphEditor);
addNodes(model);
}
My FXML code:
<?import de.tesis.dynaware.grapheditor.GraphEditorContainer?>
<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Modelo 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<GraphEditorContainer fx:id="graphEditorContainer" minWidth="0" minHeight="0" maxWidth="+Infinity" maxHeight="+Infinity"/>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
I could put the code that opens the window and draws the nodes in the handleNew function (code below), but not in the Tab.
Stage secondaryStage = new Stage();
GraphEditor graphEditor = new DefaultGraphEditor();
Scene scene = new Scene(graphEditor.getView(), 800, 600);
secondaryStage.setScene(scene);
secondaryStage.show();
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
addNodes(model);
If it's possible could you help me?
Thank You
Error on console:
javafx.fxml.LoadException: GraphEditorContainer is not a valid type.
simply means that you didn't put the import for GraphEditorContainer in the FXML file. Something like
<? import com.somecompany.somepackage.GraphEditorContainer ?>
near the top of the FXML file (with the other imports), obviously edited for the correct package name.
In the controller, it is always a mistake to initialize #FXML-annotated fields, for obvious reasons, so replace
#FXML
private GraphEditorContainer graphEditorContainer = new GraphEditorContainer();
with
#FXML
private GraphEditorContainer graphEditorContainer ;
Using custom (or 3rd party) controls in SceneBuilder is covered in Adding a custom component to SceneBuilder 2.0
I have created a sample fx application with fxml using the scene buidler.
I have mapped an action handler on scene builder and write it on the java controller class. By clicking proceed button the screen will change to another screen. But sometime screen will get stuck at that time user will click proceed button multiple time, so the system will crash.
I have added disable property of button at the beginning of action controller, but it is not happening. How to block multiple event click event or just disable button at once clicked?
#FXML
public void onBtnProceedClick() {
btnProceed.setDisable(true);
// other part of method.
}
FXML
<Button fx:id="btnProceed" maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#onBtnProceedClick" prefHeight="40.0" prefWidth="-1.0"
styleClass="btnProceed" text="" GridPane.columnIndex="1"
GridPane.rowIndex="0"
/>
The event has a getClickCount(). You can add a check to say if getClickCount() > 1 then do nothing and return.
I have a plain CheckBox in an FXML file on the same line as some other controls and labels in a HBox.
The checkBox label text-base is about 6px units lower than ALL the other text and labels on the same line (HBox).
I can manually line things up in SceneBuilder by specifying a padding-bottom value of: 6. I wanted to put that into the CSS so all checkbox labels would be "lined-up", but everthing I've tried is ignored and doesn't show in the CSS Analyzer (too).
I looked through the Checbox default styling as pointed out here:
Styling a checkbox and also:
Checkbox in the UI controls
I had similar issues with ListBox where the control is constructed from a number of components. You have to know which 'thing' is relevant. However, looking through: com/sun/javafx/scene/control/skin/
caspian/caspian.css
I can't pick the component that makes the text label lower than other text on the same line/row. Add to that, the fact that specifying the padding in the SceneBuilder designer layout, will fix the issue on a one-by-one (manual) basis, it just seems strange that it won't work for:
.check-box {
padding-bottom: 6px; /* or just 6 */
}
Does not work on the following FXML mark-up.
<HBox alignment="CENTER_LEFT" >
<children>
<CheckBox fx:id="acknowledged" alignment="TOP_LEFT" styleClass="normal" text="00">
<padding>
<Insets bottom="6.0" left="4.0" right="8.0" />
</padding>
</CheckBox>
<Button fx:id="detailButton" text="%alarm.detail.label" />
<Label fx:id="alarmType" styleClass="normal" text="%alarm.type.value">
<padding>
<Insets left="8.0" right="8.0" />
</padding>
</Label>
</children>
</HBox>
The objective is to define the padding-bottom via CSS rather than have to do it manually in the FXML:
<padding>
<Insets bottom="6.0" left="4.0" right="8.0" />
</padding>
Any ideas?
To be clear, the visual result for this row is that the checkbox itself has a base-line smaller/lower than the other elements (button, label). The CheckBox label is also subsequently "below" the other elements. If we can pad using CSS, then we don't need to manually maintain the layouts.
As a general rule, alignment problems should be solved by the layout (vs. tweaking paddings or such). So first stop to a solution could be the doc of the parent pane, here HBox:
The alignment of the content is controlled by the alignment property,
which defaults to Pos.TOP_LEFT.
That might be consistent with what you are be seeing (can't be 100% certain, though, as you forgot to include a runnable example ;-) If all other components on the line are accidentally being same height or filling the box with the checkbox smaller, it will positioned at the top of the pane.
Assumed solution is to change the pane's alignment to BASELINE_XX, quick check in code works fine for me:
private Parent getContent() {
HBox box = new HBox(new TextField("something"),
new CheckBox("soso"), new Button("hello"));
box.setAlignment(Pos.BASELINE_CENTER);
return box;
}
I just had a problem with an invisible, disabled list and a text field(visible) underneath it. I wasn't able to access the text field because I was still clicking on the list. Is there any way to have an invisible control and still be able to use the control underneath it?
Yes, use the StackPane control. This is easiest to do using the JavaFX scenebuilder.
This webpage has a topic on StackPanes.
I am assuming that you just have to fiddle with the StackPane.alignment to change which controls are usable etc. Hope this helps;
FXML:
<StackPane id="StackPane" HBox.hgrow="ALWAYS">
<children>
<ProgressBar fx:id="" disable="false" prefWidth="294.0" progress="0.0" StackPane.alignment="CENTER" />
<Slider fx:id="" prefWidth="294.0" style="" StackPane.alignment="CENTER" />
</children>
</StackPane>