Scenario : I have two panel one of them has slider and another has drag gable pane .
Case I : if Pane(i.e Drag gable ) moved in forward or backward direction .node on slider moved with respective dimension in same direction of pane moved.
Case II : this functionality works vice versa .
(Drag gable pane with slider)
(slider with drag gable Pane).
so how i can achieve it..
Thank You!
You create a property for the horizontal direction. Then you change the property whenever the slider or the pane moves. Depending on the property changes you move the pane.
public class Main extends Application {
DoubleProperty xProperty = new SimpleDoubleProperty();
double min = 0;
double max = 100;
#Override
public void start(Stage primaryStage) {
try {
Pane root = new Pane();
// rectangle
Pane pane = new Pane();
pane.setStyle("-fx-background-color:blue");
pane.setPrefSize(50, 50);
pane.relocate(min, 50);
// make rectangle movable
MouseGestures mg = new MouseGestures();
mg.makeDraggable(pane);
// slider
Slider slider = new Slider(min, max, min);
slider.valueProperty().bindBidirectional( xProperty);
root.getChildren().addAll(slider, pane);
// move horizontally, clamp horizontal movement
xProperty.addListener(new ChangeListener<Number>() {
#Override
public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
// clamp x
double x = newValue.doubleValue();
if( x < min) {
x = min;
}
if( x > max) {
x = max;
}
pane.relocate( x, pane.getBoundsInParent().getMinY());
}
});
Scene scene = new Scene(root,1024,768);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
public class MouseGestures {
final DragContext dragContext = new DragContext();
public void makeDraggable(final Node node) {
node.setOnMousePressed(onMousePressedEventHandler);
node.setOnMouseDragged(onMouseDraggedEventHandler);
}
EventHandler<MouseEvent> onMousePressedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
Node node = (Node) event.getSource();
dragContext.x = node.getBoundsInParent().getMinX() - event.getScreenX();
}
};
EventHandler<MouseEvent> onMouseDraggedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
double offsetX = event.getScreenX() + dragContext.x;
xProperty.set(offsetX);
}
};
class DragContext {
double x;
}
}
}
Related
I need a help with JavaFX. I have a program that draws lines with the mouse in the scene. When I press clear button, whole scene needs to be cleared. But only last drawn line is being cleared with this program.
When clear button is pushed, all drawn lines should be cleared. Now, only the last drawn line is being cleared.
public class Test extends Application {
private Line currentLine;
private Group root;
private ColorPicker colorPicker;
private Button clearButton;
private HBox buttons;
private Scene scene;
public void start(Stage primaryStage) {
root = new Group();
colorPicker = new ColorPicker(Color.WHITE);
clearButton = new Button("Clear");
clearButton.setOnAction(this::processActionButton);
buttons = new HBox(colorPicker, clearButton);
buttons.setSpacing(15);
root.getChildren().addAll(buttons);
scene = new Scene(root, 500, 300, Color.BLACK);
scene.setOnMousePressed(this::processMousePress);
scene.setOnMouseDragged(this::processMouseDrag);
primaryStage.setTitle("Color Lines");
primaryStage.setScene(scene);
primaryStage.show();
}
public void processMousePress(MouseEvent event) {
currentLine = new Line(event.getX(), event.getY(), event.getX(),
event.getY());
currentLine.setStroke(colorPicker.getValue());
currentLine.setStrokeWidth(3);
root.getChildren().add(currentLine);
}
public void processMouseDrag(MouseEvent event) {
currentLine.setEndX(event.getX());
currentLine.setEndY(event.getY());
}
public void processActionButton(ActionEvent event) {
root.getChildren().removeAll(currentLine);
}
public static void main(String[] args) {
launch(args);
}
}
You can have a special group for lines only:
Group groupLines = new Group();
...
root.getChildren().add(groupLines);
Add new lines into this group:
public void processMousePress(MouseEvent event) {
...
groupLines.getChildren().add(currentLine);
}
And clean only this group:
groupLines.getChildren().clear();
im trying an easy drag-pane setup. My results are funny.
Dragging an Node within an Pane results in an jumping effect?
While dragging the dot jumps to a given position and with the next drag back to the last position.
Any help?
import java.util.concurrent.atomic.AtomicReference;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.PickResult;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class DrawPolygon extends Application {
Group g ;
PickResult pickResult;
Node intersectedNode;
final AtomicReference<MouseEvent> deltaEvent = new AtomicReference<MouseEvent>();
#Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 600, 800);
stage.setScene(scene);
g = new Group();
Rectangle blue = new Rectangle();
blue.setFill(Color.BLUE);
blue.setWidth(25);
blue.setHeight(25);
blue.setX(50);
blue.setY(50);
Rectangle red = new Rectangle();
red.setFill(Color.RED);
red.setWidth(25);
red.setHeight(25);
red.setX(150);
red.setY(150);
Rectangle yellow = new Rectangle();
yellow.setFill(Color.YELLOW);
yellow.setWidth(25);
yellow.setHeight(25);
yellow.setX(250);
yellow.setY(250);
blue.addEventFilter(MouseEvent.MOUSE_CLICKED, onMouseClickedEventHandler);
red.addEventFilter(MouseEvent.MOUSE_CLICKED, onMouseClickedEventHandler);
yellow.addEventFilter(MouseEvent.MOUSE_CLICKED, onMouseClickedEventHandler);
blue.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedEventHandler);
red.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedEventHandler);
yellow.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedEventHandler);
blue.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedEventHandler);
red.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedEventHandler);
yellow.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedEventHandler);
blue.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedEventHandler);
red.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedEventHandler);
yellow.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedEventHandler);
g.getChildren().add(blue);
g.getChildren().add(red);
g.getChildren().add(yellow);
scene.setRoot(g);
stage.show();
}
EventHandler<MouseEvent> onMouseClickedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.print("C");
}
};
EventHandler<MouseEvent> onMousePressedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.print("P");
pickResult = event.getPickResult();
intersectedNode = pickResult.getIntersectedNode();
deltaEvent.set(event);
}
};
EventHandler<MouseEvent> onMouseDraggedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.print("D");
final double deltaX = event.getX() - deltaEvent.get().getX();
final double deltaY = event.getY() - deltaEvent.get().getY();
intersectedNode.setLayoutX(event.getX() - deltaX);
intersectedNode.setLayoutY(event.getY() - deltaY);
deltaEvent.set(event);
g.layout();
}
};
EventHandler<MouseEvent> onMouseReleasedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.println("R");
}
};
public static void main(String[] args) {
launch(args);
}
}
You're using positions relative to the Nodes, which messes up the calculations, and in addition to that the Node is also being moved:
newLayoutX = event.getX() - deltaX
= event.getX() - (event.getX() - deltaEvent.get().getX())
= deltaEvent.get().getX()
which is obviously wrong, since the event coordinates are in the coordinates Node the EventHandler is registered to.
Solution
Use parent coordinates
Additional Notes:
You don't get any benefit from using AtomicReference instead of a non-final field.
You are not filtering events, you're handling them; Therefore addEventHandler should be used instead of addEventFilter. Furthermore you can use the convenience methods which makes your code simpler.
Instead of adding the event handlers to every child node, you could also add the event handler to the Group which also removes the need of transforming the coordinates "manually".
Group g;
Node intersectedNode;
private Point2D dragStart;
private final Set<Node> draggable = new HashSet<>();
#Override
public void start(Stage stage) {
g = new Group();
Scene scene = new Scene(g, 600, 800);
stage.setScene(scene);
Rectangle blue = new Rectangle();
...
yellow.setY(250);
draggable.addAll(Arrays.asList(red, blue, yellow));
g.getChildren().addAll(blue, red, yellow);
g.setOnMouseClicked(onMouseClickedEventHandler);
g.setOnMousePressed(onMousePressedEventHandler);
g.setOnMouseDragged(onMouseDraggedEventHandler);
g.setOnMouseReleased(onMouseReleasedEventHandler);
scene.setRoot(g);
stage.show();
}
EventHandler<MouseEvent> onMousePressedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.print("P");
PickResult pickResult = event.getPickResult();
intersectedNode = pickResult.getIntersectedNode();
System.out.println(intersectedNode);
if (draggable.contains(intersectedNode)) {
dragStart = new Point2D(intersectedNode.getLayoutX() - event.getX(), intersectedNode.getLayoutY() - event.getY());
} else {
intersectedNode = null;
}
}
};
EventHandler<MouseEvent> onMouseDraggedEventHandler = new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
System.out.print("D");
if (intersectedNode != null) {
intersectedNode.setLayoutX(event.getX() + dragStart.getX());
intersectedNode.setLayoutY(event.getY() + dragStart.getY());
}
}
};
Here is my code, I'm trying to load a splash screen image with transparent background before my main stage starts. They come almost at the same time, but the big problem is I get a grey rectangle before anything else: .
Here is the code:
public class Menu extends Application {
private Pane splashLayout;
private Stage mainStage;
private ImageView splash;
// Creating a static root to pass to ScreenControl
private static BorderPane root = new BorderPane();
public void start(Stage splashStage) throws IOException {
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.splash = new ImageView(new Image(getClass().getResource("/splash.png").toString()));
splashStage.initStyle(StageStyle.TRANSPARENT);
showSplash(splashStage, screenSize);
// Constructing our scene using the static root
root.setCenter(new ScrollPane);
Scene scene = new Scene(root, screenSize.getWidth(), screenSize.getHeight());
showMainStage(scene);
if (splashStage.isShowing()) {
mainStage.setIconified(false);
splashStage.toFront();
FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.5), splashLayout);
fadeSplash.setDelay(Duration.seconds(3.5));
fadeSplash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
fadeSplash.setOnFinished(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent actionEvent) {
splashStage.hide();
}
});
fadeSplash.play();
}
}
private void showMainStage(Scene scene) {
mainStage = new Stage(StageStyle.DECORATED);
mainStage.setTitle("book-depot");
mainStage.getIcons().add(new Image(getClass().getResourceAsStream("/icon.png")));
mainStage.setScene(scene);
mainStage.show();
}
private void showSplash(Stage splashStage, Dimension screenSize) {
splashLayout = new StackPane();
splashLayout.setStyle("-fx-background-color: transparent;");
splashLayout.getChildren().add(splash);
Scene splashScene = new Scene(splashLayout, 690, 590);
splashScene.setFill(Color.TRANSPARENT);
splashStage.setScene(splashScene);
splashStage.show();
}
public void mainGui(String[] args) {
launch(args);
}
}
Am I doing something wrong or I really can't get a transparent background?
This is what it looks like when also the other stage loads up, but I'd like it to work like that even before the main stage loads, or at least I'd want to remove the grey rectangle you can see in the other screenshot
The grey background is your "mainStage" since you are showing splash and main stages at the same time. At the beginning while showing the splash stage you can just init (not show) the main stage and show it later when the animation finishes:
public class ModifiedMenu extends Application
{
private Pane splashLayout;
private Stage mainStage;
private ImageView splash;
// Creating a static root to pass to ScreenControl
private static BorderPane root = new BorderPane();
public void start(Stage splashStage) throws IOException {
final Dimension2D screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.splash = new ImageView(new Image(getClass().getResource("/splash.png").toString()));
splashStage.initStyle(StageStyle.TRANSPARENT);
showSplash(splashStage, screenSize);
// Constructing our scene using the static root
root.setCenter(new ScrollPane());
Scene scene = new Scene(root, screenSize.getWidth(), screenSize.getHeight());
initMainStage(scene);
if (splashStage.isShowing()) {
splashStage.toFront();
FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.5), splashLayout);
fadeSplash.setDelay(Duration.seconds(3.5));
fadeSplash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
fadeSplash.setOnFinished(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent actionEvent) {
splashStage.hide();
mainStage.show();
}
});
fadeSplash.play();
}
}
private void initMainStage(Scene scene) {
mainStage = new Stage(StageStyle.DECORATED);
mainStage.setTitle("book-depot");
mainStage.getIcons().add(new Image(getClass().getResourceAsStream("/icon.png")));
mainStage.setScene(scene);
}
private void showSplash(Stage splashStage, Dimension2D screenSize) {
splashLayout = new StackPane();
splashLayout.setStyle("-fx-background-color: transparent;");
splashLayout.getChildren().add(splash);
Scene splashScene = new Scene(splashLayout, 690, 590);
splashScene.setFill(Color.TRANSPARENT);
splashStage.setScene(splashScene);
splashStage.show();
}
public void mainGui(String[] args) {
launch(args);
}
}
I put a scalable pane in the scrollpanel then scroll way after his bigger scrollpanel setPannable (true) method does not work, I don't know how to solve, hope to get help
public class CreateAdvancedStage extends Application {
private void init(Stage primaryStage) {
BorderPane root = new BorderPane();
root.setPrefSize(200, 220);
primaryStage.setScene(new Scene(root));
ScrollPane scrolPanel = new ScrollPane();
scrolPanel.setPannable(true);//it do not work
scrolPanel.setContent(getCenterPane());
root.setCenter(scrolPanel);
}
Pane panel;
int tag = 10;
public Pane getCenterPane() {
panel = new Pane();
panel.setStyle("-fx-background-color:red");
panel.setPrefSize(100, 100);
panel.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent t) {
System.out.println("OnScroll");
//this to set panSize
if (panel != null) {
panel.setPrefSize(100 + tag, 100 + tag);
tag++;
}
}
});
return panel;
}
#Override
public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I have implemented drag'n'drop functionality very similar to How to drag and drop tab nodes between tab panes, which works fine so far, but i also add a new Stage (SideStage below) if the tab is dragged outside of the main-window/stage. The problem is, the Tab is only showing after i either drag a new Tab to the TabPane there or if i resize the window. The main part of that drag'n'drop action is happening in the GuiPartFactory in the EventHandler which get's assigned to the Label of the Tab that gets dragged. I tried all sorts of size assigning, requestLayout, etc.
Sidestage class:
private TabPane tabPane;
public SideStage(double xPos, double yPos) {
tabPane = initTabArea();
VBox root = new VBox(0,GuiPartFactory.initMenuAndTitle(this),tabPane);
Scene scene = new Scene(root, 800, 600);
setScene(scene);
scene.setOnDragExited(new DnDExitAndEntryHandler());
scene.setOnDragEntered(new DnDExitAndEntryHandler());
setX(xPos);
setY(yPos);
;
initCloseWindowHandler();
}
private void initCloseWindowHandler() {
setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent event) {
System.out.println("closing this sidestage");
MainApp.sideStages.remove(SideStage.this);
}
});
}
private TabPane initTabArea() {
final TabPane tabPane = GuiPartFactory.createTabPane();
tabPane.addEventHandler(Tab.TAB_CLOSE_REQUEST_EVENT, new EventHandler<Event>() {
#Override
public void handle(Event event) {
System.out.println("tab got closed mon!");
if (tabPane.getTabs().isEmpty()) {
SideStage.this.close();
}
}
});
VBox.setVgrow(tabPane, Priority.ALWAYS);
return tabPane;
}
public void addTab(Tab tab) {
tabPane.getTabs().add(tab);
}
And the GuiPartFactory class:
public static ResourceBundle BUNDLE = ResourceBundle.getBundle("locales/Bundle", new Locale("en", "GB"));
public static TabPane createTabPane() {
final TabPane tabPane = new TabPane();
//This event gets fired when the cursor is holding a draggable object over this tabpane
tabPane.setOnDragOver(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
final Dragboard dragboard = event.getDragboard();
if (dragboard.hasString() && dragboard.getString().equals("tab") && ((Tab) MainApp.dndTemp).getTabPane() != tabPane) {
event.acceptTransferModes(TransferMode.MOVE);
event.consume();
}
}
});
//This event gets fired when the cursor is releasing a draggable object over this tabpane (this gets only called if it has been accepted in the previos dragover event!)
tabPane.setOnDragDropped(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
System.out.println("dropped");
Tab tab = (Tab) MainApp.dndTemp;
MainApp.dndHandled = true;
tab.getTabPane().getTabs().remove(tab);
tabPane.getTabs().add(tab);
tabPane.getSelectionModel().select(tab);
event.setDropCompleted(true);
event.consume();
}
});
return tabPane;
}
public static Tab createTab(String text) {
final Tab tab = new Tab();
final Label label = new Label("Tab" + text);
tab.setGraphic(label);
StackPane pane = new StackPane();
//need to set a real size here
pane.setPrefSize(500, 500);
tab.setContent(pane);
tab.getContent().setOnDragOver(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
final Dragboard dragboard = event.getDragboard();
if (dragboard.hasString() && dragboard.getString().equals("tab") && ((Tab) MainApp.dndTemp).getTabPane() != tab.getTabPane()) {
event.acceptTransferModes(TransferMode.MOVE);
event.consume();
}
}
});
tab.getContent().setOnDragDropped(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
System.out.println("dropped");
Tab transferTab = (Tab) MainApp.dndTemp;
MainApp.dndHandled = true;
transferTab.getTabPane().getTabs().remove(transferTab);
tab.getTabPane().getTabs().add(transferTab);
tab.getTabPane().getSelectionModel().select(transferTab);
event.setDropCompleted(true);
event.consume();
}
});
label.setOnDragDetected(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
Dragboard dragboard = label.startDragAndDrop(TransferMode.MOVE);
ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.putString("tab");
MainApp.dndTemp = tab;
MainApp.dndHandled = false;
dragboard.setContent(clipboardContent);
dragboard.setDragView(new Image("img/dragcursor.png"));
event.consume();
}
});
label.setOnDragDone(new EventHandler<DragEvent>() {
#Override
public void handle(DragEvent event) {
//our dragndrop failed
if (!MainApp.dndHandled) {
//lets see if it failed because we dropped outside of our java-windows
if (!MainApp.dndInside) {
if (!MainApp.dndTemp.equals(tab)) {
System.out.println("something is wrong here");
}
System.out.println("gotta make a new window!");
SideStage sideStage = new SideStage(event.getScreenX(), event.getScreenY());
MainApp.sideStages.add(sideStage);
//just a check to make sure we don't access a null variable
if (tab.getTabPane() != null) {
tab.getTabPane().getTabs().remove(tab);
}
sideStage.addTab(tab);
sideStage.sizeToScene();
tab.getTabPane().getSelectionModel().select(tab);
System.out.println("width: " + ((StackPane) tab.getContent()).getWidth());
System.out.println("height: " + ((StackPane) tab.getContent()).getHeight());
System.out.println("width: " + tab.getTabPane().getWidth());
System.out.println("height: " + tab.getTabPane().getHeight());
sideStage.show();
}
}
}
});
return tab;
}
public static Tab createTabRandomColor(String text) {
Random rng = new Random();
Tab tab = GuiPartFactory.createTab(text);
StackPane pane = (StackPane) tab.getContent();
int red = rng.nextInt(256);
int green = rng.nextInt(256);
int blue = rng.nextInt(256);
String style = String.format("-fx-background-color: rgb(%d, %d, %d);", red, green, blue);
pane.setStyle(style);
Label label = new Label("This is tab " + text);
label.setStyle(String.format("-fx-text-fill: rgb(%d, %d, %d);", 256 - red, 256 - green, 256 - blue));
pane.getChildren().add(label);
return tab;
}
public static MenuBar initMenuAndTitle(Stage stage) {
//setting up a window title
stage.setTitle(BUNDLE.getString("title.name"));
//adding the menubar
MenuBar menuBar = new MenuBar();
//adding the base menu entry
Menu menuStart = new Menu(BUNDLE.getString("menu.start"));
Menu menuView = new Menu(BUNDLE.getString("menu.view"));
Menu menuHelp = new Menu(BUNDLE.getString("menu.help"));
menuBar.getMenus().addAll(menuStart, menuView, menuHelp);
//adding the menuitems inside the menus
MenuItem aboutItem = new MenuItem(BUNDLE.getString("menu.about"));
aboutItem.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
Dialogs popup = Dialogs.create();
popup.title(BUNDLE.getString("menu.about.title"));
popup.message(BUNDLE.getString("menu.about.message"));
popup.showInformation();
}
});
menuHelp.getItems().add(aboutItem);
MenuItem exitItem = new MenuItem(BUNDLE.getString("menu.exit"));
exitItem.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
Dialogs popup = Dialogs.create();
popup.title(BUNDLE.getString("menu.exit.title"));
popup.message(BUNDLE.getString("menu.exit.message"));
popup.actions(new Action[]{YES, NO});
Action response = popup.showConfirm();
if(response.equals(YES)) {
System.exit(0);
}
}
});
menuStart.getItems().add(exitItem);
return menuBar;
}
And finally the MainApp class:
//for handling tag drag'n'drop outside of java windows
public static Object dndTemp = null;
public static boolean dndHandled = true;
public static boolean dndInside = true;
public static Set<SideStage> sideStages = new HashSet<>();
//holding the tabs (doe)
private TabPane tabPane;
#Override
public void start(Stage stage) {
tabPane = initTabs();
VBox root = new VBox(0, GuiPartFactory.initMenuAndTitle(stage), tabPane);
Scene scene = new Scene(root, 800, 600);
stage.setScene(scene);
stage.show();
scene.setOnDragExited(new DnDExitAndEntryHandler());
scene.setOnDragEntered(new DnDExitAndEntryHandler());
}
private TabPane initTabs() {
TabPane tabPane = GuiPartFactory.createTabPane();
Tab bedraggin = GuiPartFactory.createTab("be draggin");
Tab beraggin = GuiPartFactory.createTab("be raggin");
tabPane.getTabs().add(bedraggin);
tabPane.getTabs().add(beraggin);
for (int i = 0; i < 3; i++) {
Tab tab = GuiPartFactory.createTabRandomColor("" + i);
tabPane.getTabs().add(tab);
}
VBox.setVgrow(tabPane, Priority.ALWAYS);
return tabPane;
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
public boolean removeSideStage(SideStage sideStage) {
return sideStages.remove(sideStage);
}
public void addTab(Tab tab) {
tabPane.getTabs().add(tab);
}
public void removeTab(Tab tab) {
tabPane.getTabs().remove(tab);
}
edit: A temporary workaround is to put the actual adding of the tab into the new TabPane into a runnable. But i think this is a rather bad solution:
Platform.runLater(new Runnable() {
#Override
public void run() {
sideStage.addTab(tab);
tab.getTabPane().getSelectionModel().select(tab);
}
});