How do I create a labeled separator?

edit: As it seems unclear: I want a regular JavaFx Separator (as in the second image below), but with text on . Here's an example of what it looks like in Swing (although I don't want to put anything around!):

enter image description here

It looks like it should be really simple, but the Separator class that JavaFX comes with cannot be flagged. The result should look something like this: "general parameters" or "specific parameters":

enter image description here

I found http://tiwulfx.panemu.com/2013/01/02/creating-custom-menu-separator-in-javafx/ and tried to apply this to a normal Separator, but since you cannot set content at all for this one of them didn't work (and you can't use MenuItemSeparator in other parts of the GUI and then in the menu). The options shown will be Tab in the TabPane.

Any ideas on how to do this? :)

Decision

HBox labeledSeparator = new HBox();
Label label = new Label(text);
Separator leftSeparator = new Separator();
Separator rightSeparator = new Separator();
labeledSeparator.getChildren().add(leftSeparator);
labeledSeparator.getChildren().add(label);
labeledSeparator.getChildren().add(rightSeparator);
labeledSeparator.setAlignment(Pos.CENTER);

      

+3


source to share


2 answers


Why not use an AnchorPane containing a separator and a label? The separator should be anchored to the sides of the AnchorPane, while the label can be anchored to an offset to the left, for example around 20.0. Then make the background of the label compatible with the background of your program so that the part of the Separator hidden by the label is not visible.



+3


source


It looks like you need a menu with custom CSS and a TabPane below it, below I will show you an example done with FXML.

enter image description here



<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="382.0" prefWidth="592.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children><MenuButton layoutX="0.37109375" layoutY="1.5" mnemonicParsing="false" text="MenuButton">
  <items>
    <MenuItem mnemonicParsing="false" text="Action 1" />
    <MenuItem mnemonicParsing="false" text="Action 2" />
  </items>
</MenuButton><MenuButton layoutX="99.0" layoutY="1.5" mnemonicParsing="false" text="MenuButton">
  <items>
    <MenuItem mnemonicParsing="false" text="Action 1" />
    <MenuItem mnemonicParsing="false" text="Action 2" />
  </items>
</MenuButton><MenuButton layoutX="197.62890625" layoutY="1.5" mnemonicParsing="false" text="MenuButton">
  <items>
    <MenuItem mnemonicParsing="false" text="Action 1" />
    <MenuItem mnemonicParsing="false" text="Action 2" />
  </items>
</MenuButton><Separator layoutX="2.0" layoutY="24.0" prefHeight="5.0" prefWidth="590.0" /><Pane layoutX="2.0" layoutY="33.0" prefHeight="350.0" prefWidth="590.0">
<children><TabPane layoutY="-8.0" prefHeight="350.0" prefWidth="590.0" tabClosingPolicy="UNAVAILABLE">
  <tabs>
    <Tab text="Start">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
      </content>
    </Tab>
    <Tab text="ConvergenceRate1">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
      </content>
    </Tab><Tab text="FitneesFunction1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
  </tabs>
</TabPane>
</children></Pane>
</children></Pane>

      

+1


source







All Articles