Coder Social home page Coder Social logo

windowcontrollerfx's Introduction

WindowControllerFx

Custom controller implementation to facilitate stage creation

Usage

1 - Download .jar and add to your project classpath

Working with FXML

2 - Create your FXML layout on SceneBuilder or preffered IDE

3 - Extend your FXML controller of WindowControllerFx

  public class MyController extends WindowControllerFx
  

4 - Override getFXML method passing the location of your FXML layout

    @Override
    public String getFXML() {
        return "/com/example/view/my-layout.fxml";
    }
  

5 - Override initialize method if you want node initialization control

6 - Instance your controller and use one of show methods to display your stage

  // shows decorated stage
  new MyController().show();
  
  // shows modal decorated stage
  new MyController()
              .setParent(anParent)
              .showModal();
  
  // shows modal dialog stage
  new MyController()
              .setParent(anParent)
              .showAsDialog();
              
   // shows undecorated stage
  new MyController().showUndecorated(transparent?);
  

Working with Region

If you don't work with FXML, just override the getRootPane method instead of getFXML, see below:

    @Override
    public Region getRootPane() {
      BorderPane pane = new BorderPane();

       MenuBar bar = new MenuBar(
          new Menu("File"),
          new Menu("Edit"),
          new Menu("Exit")
       );

        pane.setTop(bar);

        pane.setPrefSize(500, 500);

        pane.setCenter(new TextArea("Some text"));

        return pane;
    }
  

Feel free to contribute.

See example in sources to full usage.

License

Copyright 2017 Fernando Andrauss

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

windowcontrollerfx's People

Contributors

andrauss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

esousa77

windowcontrollerfx's Issues

Failed to load Window

Olá.

Estou tentando fechar uma tela e abrir outra. Mas recebo a seguinte exception:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Failed to load window
	at br.com.fandrauss.fx.gui.WindowControllerFx.createStage(WindowControllerFx.java:388)
	at br.com.fandrauss.fx.gui.WindowControllerFx.showUndecorated(WindowControllerFx.java:335)

Esse é meu main, onde chamo a tela de login:

public class main extends Application {
    @Override
    public void start(Stage primaryStage) throws IOException {
        new LoginController().showUndecorated(false);
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Após a validação do login, é chamado o método nextStage:

    @Override
    public void nextStage(Stage stage) {
        stage.close();
        Platform.runLater(() -> {
            new SelectorController().showUndecorated(false);
        });
    }

E é na instanciação do novo controller que a exception é recebida.

public class SelectorController extends WindowControllerFx {

    @FXML
    private ImageView fecharImage;

    @FXML
    private ImageView minimizarImage;

    @FXML
    private JFXComboBox<Mosaicos> comboBox;

    private List<Mosaicos> mosaicos = new ArrayList<>();

    @FXML
    private JFXButton confirmButton;

    private void listarMosaicos() {
        MosaicSelectorImpl model = new MosaicSelectorImpl();
        List<Mosaicos> mosaicos = model.listar();
        ObservableList<Mosaicos> obsMosaicos = FXCollections.observableArrayList(mosaicos);
        comboBox.setItems(obsMosaicos);

    }

    private void minimizarJanela() {
        Stage stage = (Stage) confirmButton.getScene().getWindow();
        stage.setIconified(true);
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        minimizarImage.setOnMouseClicked(event -> minimizarJanela());
        fecharImage.setOnMouseClicked(event -> System.exit(0));
        listarMosaicos();
    }

    @Override
    public String getFXML(){
        return "fxml/mosaicSelectorScene.fxml";
    }

O que pode ser?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.