How do we Move/ Drag a Stage accross the screen in JAVAFX?
I've been trying to move my project from JAVA's Swing to JAVA-FX but have
been unsuccessful because of one detail. I've had my Stage set
undecorated, which disables the "Drag via Title Bar feature". I'd like to
get that back (the drag feature), which is where I am totally stuck.
The way I'd like to do it to have Drag effected via a call to a method in
the Controller Class, like how I did with the WindowClose() method.
Please, if you can, could you show how to do so by integrating your ideas
around this problem somewhere in my code below. I just started studying
JAVA-FX and I'm having difficulties integrating the other many examples
I've come accross that solve this dilemma in my code.
Any help will be much appreciated.
post script:
Any ideas are welcome, even those implementing the drag via a method
placed in the main Class (I've noted that there seems to be more
difficulty calling methods on the Stage from another external Class/
Controller Class). I'll be much glad with anything I can get - any help is
useful. I'd, however, like to learn how to share data between Classes in
JAVA-FX.
The CODE:
// Main Class
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Fxmltableview extends Application {
public static String pageSource = "fxml_tableview.fxml";
public static Scene scene;
@Override
public void start(Stage stage) throws Exception {
stage.initStyle(StageStyle.UNDECORATED);
stage.initStyle(StageStyle.TRANSPARENT);
Parent root = FXMLLoader.load(getClass().getResource(pageSource));
scene = new Scene(root, Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
// Controller
import javafx.application.Platform;
import javafx.event.ActionEvent;
public class FXMLTableViewController {
public void WindowClose (ActionEvent event) {
Platform.exit();
}
}
No comments:
Post a Comment