I am building my fxml programmatically.
Now I'm adding a titledpanes to my accordion and in those titledpane I have setContent to a gridpane that is defined in the loop.
The result screen shows all titledpanes i've added. It shows the title of the titledpanes I set. But it only shows the content of the last titledpane I added.
I don't understand why, as the reference to the titledpane still exists in the arraylist I made and in my understanding the content(Node) I have set is saved there. And it looks like the row and columnconstraints are working for all instances, which I think means that the grid has been found for every TitledPane but every but the last one is without content.
Public class FXMLController Implements Initializable {
#FXML private VBox vboxDrills;
//NonFXML
private ArrayList<TitledPane> lsttpDrillList;
private Accordion accDrill;
public void initLayout(ArrayList<Drill> drills){
accDrill = new Accordion();
lsttpDrillList = new ArrayList<>();
TitledPane tpDrill; //AP = AccordionPane
GridPane gpTopDrill;
Accordion accDrillStep;
GridPane gpBottomDrill;
//gpTopDrill
ColumnConstraints cc1gpTopDrill = new ColumnConstraints();
cc1gpTopDrill.setHgrow(Priority.SOMETIMES);
cc1gpTopDrill.setMaxWidth(Double.NEGATIVE_INFINITY);
cc1gpTopDrill.setMinWidth(10.0);
cc1gpTopDrill.setPrefWidth(200.0);
ColumnConstraints cc2gpTopDrill = new ColumnConstraints();
cc2gpTopDrill.setHgrow(Priority.SOMETIMES);
cc2gpTopDrill.setMaxWidth(Double.NEGATIVE_INFINITY);
cc2gpTopDrill.setMinWidth(10.0);
cc2gpTopDrill.setPrefWidth(400.0);
RowConstraints rc1gpTopDrill = new RowConstraints();
rc1gpTopDrill.setMaxHeight(Double.NEGATIVE_INFINITY);
rc1gpTopDrill.setMinHeight(Double.NEGATIVE_INFINITY);
rc1gpTopDrill.setPrefHeight(35.0);
rc1gpTopDrill.setVgrow(Priority.SOMETIMES);
Label lblDrillID = new Label();
lblDrillID.minHeight(Double.NEGATIVE_INFINITY);
lblDrillID.minWidth(Double.NEGATIVE_INFINITY);
lblDrillID.setText("Drill ID:");
Label lblActualID = new Label();
lblActualID.minHeight(Double.NEGATIVE_INFINITY);
lblActualID.minWidth(Double.NEGATIVE_INFINITY);
Label lblDrillTitle = new Label();
lblDrillTitle.setText("Drill Title:");
TextField txtDrillTitleEdit = new TextField();
//end gpTopDrill
for(int i=0; i<drills.size(); i++){
//new instance and title
Drill drill = drills.get(i);
tpDrill = new TitledPane();
if(!drill.getTitle().isEmpty()){
tpDrill.setText(drill.getTitle());
}else{
tpDrill.setText("Drill" + drill.getID());
}
tpDrill.setId("drillPane" + (i));
//gpTopDrill
lblActualID.setText(Integer.toString(drill.getID()));
txtDrillTitleEdit.setId("drillTitleEdit" + (i));
txtDrillTitleEdit.setText(drill.getTitle());
GridPane.setConstraints(lblDrillID, 0, 0);
GridPane.setConstraints(lblActualID, 1, 0);
GridPane.setConstraints(lblDrillTitle, 0, 1);
GridPane.setConstraints(txtDrillTitleEdit, 1, 1);
gpTopDrill = new GridPane();
gpTopDrill.getColumnConstraints().addAll(cc1gpTopDrill, cc2gpTopDrill);
gpTopDrill.getRowConstraints().addAll(rc1gpTopDrill, rc1gpTopDrill);
gpTopDrill.getChildren().addAll(lblDrillID, lblActualID, lblDrillTitle, txtDrillTitleEdit);
//end gpTopDrill
//accDrillStep
//end accDrillStep
//gpBottomDrill
//end gpBottomDrill
//put VBox in drillpane
tpDrill.setContent(gpTopDrill);
lsttpDrillList.add(tpDrill);
}
accDrill.getPanes().setAll(lsttpDrillList);
accDrill.layoutXProperty().set(8.0);
accDrill.layoutYProperty().set(7.0);
accDrill.setExpandedPane(lsttpDrillList.get(0));
vboxDrills.getChildren().add(0, accDrill);
}
...
}
Example
Related
My Problem
I'm trying to resize a column and, it works as inteended at first. But as soon as the width of the column is the same as the minimum width, it doesn't work anymore.
It's like stuck. As user, you can't make it bigger unless you resize the whole window.
I know roughly what the problem is. I think it is because there is no space to make a cell bigger.
What I tried
What I know is that if I removed this line, it would work.
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
But I need this line for my programm, because the number of columns is different from file to file. I also need this line because every column should be the same size after loading the file (number of columns / width from tableview = column width).
MCVE
public class GuiLayout extends Application {
private Scene mainScene;
private Stage mainStage;
private VBox mainBox;
private TableView<String> tableView;
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
initTable();
mainStage = new Stage();
mainScene = new Scene(mainVBox(), 1000, 600);
ObservableList observableList = FXCollections.observableArrayList("1", "1234", "Avenue 1", "17", "Second", "Married", "M", "admin", "admin#admin.com", "Just", "Test", "no");
tableView.setItems(observableList);
tableView.prefWidthProperty().bind(mainBox.widthProperty());
tableView.prefHeightProperty().bind(mainBox.heightProperty());
mainStage.setScene(mainScene);
mainStage.show();
}
private GridPane mainGrid() {
GridPane gridPane = new GridPane();
gridPane.setVgap(10);
gridPane.setHgap(10);
gridPane.add(tableView, 0, 2);
return gridPane;
}
private VBox mainVBox() {
mainBox = new VBox();
mainBox.prefWidthProperty().bind(mainStage.widthProperty().multiply(0.8));
mainBox.setPadding(new Insets(10, 10, 10 ,10));
mainBox.getChildren().add(mainGrid());
return mainBox;
}
private TableView initTable() {
tableView = new TableView<>();
TableColumn<String, String> numberCol
= new TableColumn<>("Nr.");
TableColumn<String, String> plzCol
= new TableColumn<>("PLZ");
TableColumn<String, String> adressCol
= new TableColumn<>("Adress");
TableColumn<String, String> houseNumber
= new TableColumn<>("House number");
TableColumn<String, String> floorCol
= new TableColumn<>("Floor");
TableColumn<String, String> familyStatusCol
= new TableColumn<>("Family Status");
TableColumn<String, String> genderCol
= new TableColumn<>("Gender");
TableColumn<String, String> userNameCol //
= new TableColumn<>("User Name");
TableColumn<String, String> emailCol//
= new TableColumn<>("Email");
TableColumn<String, String> firstNameCol //
= new TableColumn<>("First Name");
TableColumn<String, String> lastNameCol //
= new TableColumn<>("Last Name");
// Active Column
TableColumn<String, Boolean> activeCol//
= new TableColumn<>("Active");
tableView.getColumns().addAll(numberCol, plzCol, adressCol, houseNumber, floorCol, familyStatusCol, genderCol, userNameCol, emailCol, firstNameCol, lastNameCol, activeCol);
for (int i = 0; tableView.getColumns().size() > i; i++){
tableView.getColumns().get(i).setMinWidth(100);
}
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
return tableView;
}
}
In the end, I expect that you can resize the column (make it bigger) when every columns has the minimum width.
Thank you for your help.
Edit:
I know that I need a customized Callback but I don't really know how I should realized it.
I tried things like setting the Property to tableView.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); and set the size of the column hardcoded.
for (int o = 0; o < tableView.getColumns().size(); o++) {
tableView.getColumns().get(o).prefWidthProperty().bind(tableView.widthProperty().divide(tableView.getColumns().size()));
Can anyone help me with the Callback? I'm not asking you if you can make the Callback for me (but if you want go for it) more I'm asking if you can give me a hint or something how I could realise it.
I would like to add items to a table dynamically.
I do it like this:
public class TestApp extends Application {
public static void main(final String[] args) {
launch(args);
}
private final AtomicLong counter = new AtomicLong();
#Override
public void start(final Stage primaryStage) {
final VBox root = new VBox(5);
root.setPadding(new Insets(10));
root.setAlignment(Pos.CENTER);
final TableView<String> tableView = new TableView<>();
final TableColumn<String, String> column = new TableColumn<>("Text");
column.setCellValueFactory(f -> new SimpleStringProperty(f.getValue()));
tableView.getColumns().add(column);
// Add some sample items to our TableView
for (int i = 0; i < 100; i++) {
tableView.getItems().add("Item #" + counter.incrementAndGet());
}
final Button button = new Button("Add items");
final long oldElement = counter.get();
button.setOnAction(e -> {
// Add more elements
for (int i = 0; i < 10; i++) {
tableView.getItems().add("Item #" + counter.incrementAndGet());
}
tableView.scrollTo("Item #" + oldElement);
});
root.getChildren().add(button);
root.getChildren().add(tableView);
// Show the Stage
primaryStage.setWidth(300);
primaryStage.setHeight(300);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}
(Example taken from here)
What I would like to change now, is, that when the table is already scrolled down completely, and I add more items, the table automatically scrolls down.
The 'scroll-state' seems to be maintained, which is why I still see the very bottom of the table (and the new elements).
How can I add items to the table but keeping the scroll at the current position / current row?
The 'scrollTo' works, but moves the last element from the bottom of the view to the top, which is also a litte irritating.
I got a problem with the depth buffer in JavaFX.
I started a simluation and tried now to rotate my windwheels around the Y-Axis.
Normally it is just showing my pane with the scene and i can click every button and chart i added to my scene.
As i noticed the best way to hide the different parts of my windwheel is the depth buffer. If i set him on true i cant even click on my scene and make changes.
Here i got one picture with
with depth buffer
and without the depth buffer
without depth buffer
So anyone got an idea what went wrong by activating the buffer ?
This is my start methode:
public class Main extends Application {
Stage primaryStage;
Pane region;
Scene simulation;
Group root;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
region = new Pane();
root = new Group();
simulation = new Scene(root, 1200, 1000,true);
simulation.setCamera(new PerspectiveCamera());
primaryStage.setScene(simulation);
simulation.setRoot(region);
new GUI(simulation, region);
primaryStage.show();
}}
and this is the GUI class where i load everything from:
public class GUI {
Pane pane;
ComboBox<String> windpark;
ObservableList<String> recordsWindpark;
ObservableList<String> recrodsWindDirection;
Label settings;
Label windDirection;
Label windStrength;
Label birds;
Label bos;
Label fire;
Label totalKW;
Button start;
Button stop;
Button reset;
Button add;
Button delete;
Button x1;
Button x2;
Button x4;
Button chartRenew;
Line bottomLine;
Line sideline;
Line settingLine;
CheckBox birdsYes;
CheckBox birdsNo;
CheckBox fireYes;
CheckBox fireNo;
CheckBox bosYes;
CheckBox bosNo;
ComboBox<String> windDirectionCombo;
TextField windDegree;
Box gamefield;
Scene scene;
Group root;
int scalingForGUI;
Double timeData;
String windStrenghtData;
WindWheel rad;
WindWheel rad2;
WindWheel rad3;
WindWheel rad4;
WindWheel rad5;
WindWheel rad6;
public GUI(Scene scene, Pane pane) {
this.pane = pane;
root = new Group();
this.scene = scene;
recordsWindpark = FXCollections.observableArrayList("Windpark Ostsee", "Windpark Nordsee","Delete");
recrodsWindDirection = FXCollections.observableArrayList("Nord - Nord/Ost", "Ost - Süd/Ost", "Süd - Süd/West",
"West - Nord/West");
settings = new Label("Settings");
settings.setLayoutX(900);
settings.setLayoutY(30 - scalingForGUI);
windpark = new ComboBox<>(recordsWindpark);
windpark.setLayoutX(900);
windpark.setLayoutY(90 - scalingForGUI);
windDirection = new Label("Windrichtung");
windDirection.setLayoutX(900);
windDirection.setLayoutY(200 - scalingForGUI);
windStrength = new Label("Windstaerke");
windStrength.setLayoutX(900);
windStrength.setLayoutY(300 - scalingForGUI);
birds = new Label("Voegel");
birds.setLayoutX(900);
birds.setLayoutY(540 - scalingForGUI);
bos = new Label("Boeen");
bos.setLayoutX(900);
bos.setLayoutY(600 - scalingForGUI);
fire = new Label("Brand");
fire.setLayoutX(900);
fire.setLayoutY(660 - scalingForGUI);
totalKW = new Label("Gesamt KW");
totalKW.setLayoutX(900);
totalKW.setLayoutY(750 - scalingForGUI);
start = new Button("Start");
start.setLayoutX(30);
start.setLayoutY(700);
stop = new Button("Stop");
stop.setLayoutX(80);
stop.setLayoutY(700);
reset = new Button("Reset");
reset.setLayoutX(130);
reset.setLayoutY(700);
add = new Button("Add");
add.setLayoutX(600);
add.setLayoutY(700);
delete = new Button("Delete");
delete.setLayoutX(650);
delete.setLayoutY(700);
x1 = new Button("x1");
x1.setLayoutX(550);
x1.setLayoutY(100);
x2 = new Button("x2");
x2.setLayoutX(600);
x2.setLayoutY(100);
x4 = new Button("x4");
x4.setLayoutX(650);
x4.setLayoutY(100);
gamefield = new Box(600, 40, 600);
gamefield.setMaterial(new PhongMaterial(Color.GREENYELLOW));
gamefield.getTransforms().add(new Rotate(10, 0, 0, 0, Rotate.X_AXIS));
gamefield.getTransforms().add(new Rotate(20, 0, 0, 0, Rotate.Y_AXIS));
gamefield.setLayoutX(400);
gamefield.setLayoutY(500);
gamefield.setTranslateZ(1);
bottomLine = new Line(0, 650, 850, 650);
sideline = new Line(850, 0, 850, 1000);
settingLine = new Line(850, 140, 1500, 140);
birdsYes = new CheckBox("Yes");
birdsYes.setLayoutX(900);
birdsYes.setLayoutY(560 - scalingForGUI);
birdsNo = new CheckBox("No");
birdsNo.setLayoutX(970);
birdsNo.setLayoutY(560 - scalingForGUI);
fireYes = new CheckBox("Yes");
fireYes.setLayoutX(900);
fireYes.setLayoutY(680 - scalingForGUI);
fireNo = new CheckBox("No");
fireNo.setLayoutX(970);
fireNo.setLayoutY(680 - scalingForGUI);
bosYes = new CheckBox("Yes");
bosYes.setLayoutX(900);
bosYes.setLayoutY(620 - scalingForGUI);
bosNo = new CheckBox("No");
bosNo.setLayoutX(970);
bosNo.setLayoutY(620 - scalingForGUI);
chartRenew = new Button("Renew Charts");
chartRenew.setLayoutX(720);
chartRenew.setLayoutY(100);
windDirectionCombo = new ComboBox<>(recrodsWindDirection);
windDirectionCombo.setLayoutX(900);
windDirectionCombo.setLayoutY(230);
windDirectionCombo.setOnAction(e -> {
switchtingWind();
});
windDegree = new TextField("Gradzahl");
windDegree.setLayoutX(900);
windDegree.setLayoutY(260);
windDegree.setEditable(false);
pane.getChildren().addAll(gamefield, settings, windpark, windDirection, windStrength, birds, bos, fire, totalKW,
start, stop, reset, add, delete, x1, x2, x4, bottomLine, sideline, settingLine, birdsYes, birdsNo,
fireYes, fireNo, bosYes, bosNo, windDirectionCombo, windDegree, chartRenew);
scene.setRoot(pane);
String artLeistung = "Leistung";
Chart chartLeistung = new Chart(pane, artLeistung);
chartLeistung.enableEventHandler();
chartLeistung.setLayout(835, 310);
}
I hope someone can help me.
Thanks forward!
In a JavaFX TableView, how can I
Create a multiline column?
Center its content?
And set background color for each (entire) line?
I managed to create a multiline column using a custom CellFactory. I'm also aware of setAlignment(Pos.CENTER) and setTextAlignment(TextAlignment.CENTER) to center text. However, the text in my sample app is not centered properly per line. Furthermore, I did not manage to set a background color on the Text objects. Now my approach is to add a Pane for each line, which works fine. But how do I make the Pane fill the column's entire width and 1/3rd of its height?
As a starting point, this is how I would expect the code to be (though, I'm aware it's not doing what I want):
multiCol.setCellFactory(new Callback<TableColumn<Person, Person>, TableCell<Person, Person>>() {
#Override public TableCell<Person, Person> call(TableColumn<Person, Person> multiCol) {
return new TableCell<Person, Person>() {
private Group grp = null;
#Override public void updateItem(final Person person, boolean empty) {
super.updateItem(person, empty);
this.setAlignment(Pos.CENTER);
if (!isEmpty()) {
Text text = new Text(person.getFirstName());
text.setX(0);
text.setY(0);
text.setTextAlignment(TextAlignment.CENTER); // Center text?
Pane pane = new Pane();
pane.setStyle("-fx-background-color: #66BB66;");
pane.setLayoutX(0);
pane.setLayoutY(0);
pane.setPrefHeight(20);
pane.setPrefWidth(this.prefWidth(-1)); // Column width?
// -----
Text text2 = new Text(person.getLastName());
text2.setX(0);
text2.setY(20);
text2.setTextAlignment(TextAlignment.CENTER); // Center text?
Pane pane2 = new Pane();
pane2.setStyle("-fx-background-color: #79A8D8;");
pane2.setLayoutX(0);
pane2.setLayoutY(20);
pane2.setPrefHeight(20);
pane2.setPrefWidth(this.prefWidth(-1)); // Column width?
// -----
Text text3 = new Text(person.getEmail());
text3.setX(0);
text3.setY(40);
text3.setTextAlignment(TextAlignment.CENTER); // Center text?
Pane pane3 = new Pane();
pane3.setStyle("-fx-background-color: #FF8888;");
pane3.setLayoutX(0);
pane3.setLayoutY(40);
pane3.setPrefHeight(20);
pane3.setPrefWidth(this.prefWidth(-1)); // Column width?
// -----
Group grp = new Group();
grp.getChildren().add(pane);
grp.getChildren().add(text);
grp.getChildren().add(pane2);
grp.getChildren().add(text2);
grp.getChildren().add(pane3);
grp.getChildren().add(text3);
setGraphic(grp);
setStyle("-fx-padding: 0 0 0 0;");
}
}
};
}
});
I'm expecting an output like this:
For a full, compilable code sample please check out this pastebin.
Use a suitable layout pane (e.g. a VBox), and add Labels to it. You can configure the labels to fill the width of a VBox using VBox.setHgrow(...). You also need to set the maximum width of the label to allow it to grow.
As an aside, it is not good practice to re-create the controls every time the updateItem(...) method is called. Create them once and then just configure them in the updateItem(...) method with the required data.
Example:
TableColumn<Person, Person> multiCol = new TableColumn<>("Multiline");
multiCol.setCellValueFactory(cellData ->
new ReadOnlyObjectWrapper<Person>(cellData.getValue()));
multiCol.setCellFactory(column -> new TableCell<Person, Person>() {
private VBox graphic ;
private Label firstNameLabel ;
private Label lastNameLabel ;
private Label emailLabel ;
// Anonymous constructor:
{
graphic = new VBox();
firstNameLabel = createLabel("#66BB66");
lastNameLabel = createLabel("#79A8D8");
emailLabel = createLabel("#FF8888");
graphic.getChildren().addAll(firstNameLabel,
lastNameLabel, emailLabel);
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
private final Label createLabel(String color) {
Label label = new Label();
VBox.setVgrow(label, Priority.ALWAYS);
label.setMaxWidth(Double.MAX_VALUE);
label.setStyle("-fx-background-color: "+color+" ;");
label.setAlignment(Pos.CENTER);
return label ;
}
#Override
public void updateItem(Person person, boolean empty) {
if (person == null) {
setGraphic(null);
} else {
firstNameLabel.setText(person.getFirstName());
lastNameLabel.setText(person.getLastName());
emailLabel.setText(person.getEmail());
setGraphic(graphic);
}
}
});
I have this simple example with JavaFX tabs:
public class test extends Application
{
private BorderPane root;
// Navigation Utilization
private ActionTabs actiontabs;
#Override
public void start(Stage primaryStage)
{
// Set Main Window Label
primaryStage.setTitle("Desktop Client");
Image iv = new Image(getClass().getResource("/images/internet-icon.png").toExternalForm());
primaryStage.getIcons().add(iv);
root = new BorderPane();
root.setLeft(getLeftHBox(primaryStage, root));
Scene scene = new Scene(root, 1000, 1000, Color.WHITESMOKE); // Set main Stage color
primaryStage.setScene(scene);
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
// Set Stage boundaries to visible bounds of the main screen
primaryStage.setX(primaryScreenBounds.getMinX());
primaryStage.setY(primaryScreenBounds.getMinY());
primaryStage.setWidth(primaryScreenBounds.getWidth()); // Maximum width of the display
primaryStage.setHeight(primaryScreenBounds.getHeight()); // Maximum height of the display
primaryStage.show();
}
public static void main(String[] args)
{
launch(args);
}
private HBox getLeftHBox(Stage primaryStage, BorderPane root)
{
HBox hbox = new HBox();
TabPane tabPane = new TabPane();
BorderPane mainPane = new BorderPane();
tabPane.setStyle("-fx-font-size: 12pt;"); // Set global size for the font
// Create Tabs
Tab tabA = new Tab();
tabA.setText("Main Component");
tabA.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
tabA.setClosable(false);
// Add something in Tab
StackPane tabA_stack = new StackPane();
tabA_stack.setAlignment(Pos.CENTER);
tabA_stack.getChildren().add(new Label("Label#Tab A"));
tabA.setContent(tabA_stack);
tabPane.getTabs().add(tabA);
Tab tabB = new Tab();
tabB.setText("Second Component");
tabB.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
tabB.setClosable(false);
// Add something in Tab
StackPane tabB_stack = new StackPane();
tabB_stack.setAlignment(Pos.CENTER);
tabB_stack.getChildren().add(new Label("Label#Tab B"));
tabB.setContent(tabB_stack);
tabPane.getTabs().add(tabB);
Tab tabC = new Tab();
tabC.setText("Last Component");
tabC.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
tabC.setClosable(false); // da se mahne opciqta da se zatvarq tab
// Add something in Tab
StackPane tabC_vBox = new StackPane();
tabC_vBox.setAlignment(Pos.CENTER);
tabC_vBox.getChildren().add(new Label("Label#Tab C"));
tabC.setContent(tabC_vBox);
tabPane.getTabs().add(tabC);
mainPane.setCenter(tabPane);
mainPane.setPrefSize(300, 500);
//mainPane.setLayoutX(5); // Horizontal Position
mainPane.setLayoutY(32); // Vertical Position
hbox.getChildren().addAll(mainPane);
return hbox;
}
}
I want when I double click on a tab name to maximize the size of the body of the tab and make it the same width and height as the size of the application. Similar for example to Eclipse IDE tabs. Is this possible with JavaFX?
EDIT
This is the code that I have tested.
public BorderPane initNavigation(Stage primaryStage)
{
VBox stackedTitledPanes = createStackedTitledPanes();
ScrollPane scroll = makeScrollable(stackedTitledPanes);
final TabPane tabPane = new TabPane();
final BorderPane mainPane = new BorderPane();
final Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
tabPane.setStyle("-fx-font-size: 12pt;"); // Set global size for the font
// Create Tabs
Tab tabA = new Tab();
tabPane.setOnMouseClicked(new EventHandler<MouseEvent>()
{
private double sizeX, sizeY;
private boolean first = true;
#Override
public void handle(MouseEvent me)
{
if (first)
{
sizeX = mainPane.getWidth();
sizeY = mainPane.getHeight();
first = false;
}
if (me.getButton().equals(MouseButton.PRIMARY) && me.getClickCount() % 2 == 0)
{
if (sizeX != mainPane.getWidth() || sizeY != mainPane.getHeight())
{
mainPane.setPrefSize(sizeX, sizeY);
}
else
{
mainPane.setPrefSize(primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight());
//mainPane.toFront();
}
}
}
});
tabA.setText("Main Component");
tabA.setContextMenu(makeTabContextMenu(tabA, tabPane)); // Set right mouse click menu
// Add something in Tab
StackPane tabA_stack = new StackPane();
tabA_stack.setAlignment(Pos.CENTER);
tabA_stack.getChildren().add(scroll);
tabA.setContent(tabA_stack);
tabPane.getTabs().add(tabA);
Tab tabB = new Tab();
tabB.setText("Second Component");
tabB.setContextMenu(makeTabContextMenu(tabB, tabPane)); // Set right mouse click menu
// Add something in Tab
StackPane tabB_stack = new StackPane();
tabB_stack.setAlignment(Pos.CENTER);
tabB_stack.getChildren().add(new Label("Label#Tab B"));
tabB.setContent(tabB_stack);
tabPane.getTabs().add(tabB);
Tab tabC = new Tab();
tabC.setText("Last Component");
tabC.setContextMenu(makeTabContextMenu(tabC, tabPane)); // Set right mouse click menu
// Add something in Tab
StackPane tabC_vBox = new StackPane();
tabC_vBox.setAlignment(Pos.CENTER);
tabC_vBox.getChildren().add(new Label("Label#Tab C"));
tabC.setContent(tabC_vBox);
tabPane.getTabs().add(tabC);
mainPane.setCenter(tabPane);
mainPane.setPrefSize(300, 500);
//mainPane.setLayoutX(5); // Horizontal Position
mainPane.setLayoutY(32); // Vertical Position
scroll.setPrefSize(395, 580);
scroll.setLayoutX(5);
scroll.setLayoutY(32);
return mainPane;
}
The problem is how I can cover the stage with the tab code when I double click on the tab name?
You required to add few lines to your code, here is a sample for you,
.....
Tab tabA = new Tab();
Label tabALabel = new Label("Main Component");
tabA.setGraphic(tabALabel);
tabALabel.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
if (mouseEvent.getClickCount() == 2) {
mainPane.setPrefSize(500, 500); //Your required size
}
}
}
});
....
Try this, and tell if there's any difficulty.
You could create another BorderPane which contains your root = new BorderPane();
in Center, and replace it with the Tabpanel on doubleclick.
Resulting in:
rootRoot = new BorderPane();
BorderPane root = new BorderPane();
root.setLeft(getLeftHBox(primaryStage, root));
rootRoot.setCenter(root);
Scene scene = new Scene(rootRoot, 1000, 1000, Color.WHITESMOKE); // Set main Stage color
with "rootRoot" being the new root (great Name, i know ^^), and
Label tabALabel=new Label("Label#Tab A");
tabALabel.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
if (mouseEvent.getClickCount() == 2) {
//mainPane.setPrefSize(500, 500); //Your required size
rootRoot.setCenter(mainPane);
}
}
}
});
for maximizing.