Created
February 1, 2017 22:22
-
-
Save Andrauss/4c8e87bb0405b5d6187f0becdb883f23 to your computer and use it in GitHub Desktop.
Exemplo com Window Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WindowController; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
import javafx.fxml.FXML; | |
import javafx.scene.control.Menu; | |
import javafx.scene.control.MenuBar; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.AnchorPane; | |
import javafx.scene.layout.BorderPane; | |
import javafx.scene.layout.Region; | |
import javafx.scene.layout.StackPane; | |
import javafx.util.Duration; | |
/** | |
* FXML Controller class | |
* | |
* @author Fernando Andrauss | |
*/ | |
public class TelaExemploController extends WindowController { | |
/* | |
Para chamar a tela use um dos métodos abaixo: | |
-> Janela com botões: de maximizar, minimizar, fechar | |
TelaExemploController().show(pai); | |
-> Janela com botões: de maximizar, minimizar, fechar e em modal | |
TelaExemploController().showModal(pai); | |
-> Dialog com botões: fechar e em modal | |
TelaExemploController().showAsDialg(pai); | |
-> Dialog sem decoração de janela e em modal | |
-> transparente: se true o fundo da janela fica tranparente, false fundo normal | |
TelaExemploController().showUndecorated(pai, tranparente?); | |
Métodos Adicionais: | |
TelaExemploController() | |
.setTitulo("Frame de Cadastro") -> Use setTitulo para definir o títuo da janela | |
.setIcone(new Image("caminho_da_imagem")) -> Use setIcone para definir o ícone da janela | |
.show(pai) | |
.maximize() -> Use maximize para Maximizar a janela | |
.minimize() -> Use minimize para minimizar | |
.telaCheia(); -> Use telaCheia para entrar em tela cheia | |
.sairTelaCheia(); -> Use sairTelaCheia para sair da tela cheia | |
*/ | |
@FXML | |
private AnchorPane pane; | |
@FXML | |
private TextField tfTitulo; | |
/** | |
* Sobreescrevendo o método que define o layout | |
* | |
* @return | |
*/ | |
@Override | |
public String getFXML() { | |
return "/layout/tela_exemplo.fxml"; | |
} | |
@Override | |
public void initialize(URL url, ResourceBundle rb) { | |
// Inicialização de componentes | |
System.out.println("INITIALIZE " + getClass().getName()); | |
} | |
/** | |
* Ações definidas no layout | |
*/ | |
@FXML | |
void ActionShow() { | |
new TelaExemploController() | |
.setTitulo(tfTitulo.getText()) | |
.show(getWindow()) | |
.telaCheia(); | |
} | |
@FXML | |
void ActionShowAsDialog() { | |
new TelaExemploController() | |
.setTitulo(tfTitulo.getText()) | |
.showAsDialg(getWindow()); | |
} | |
@FXML | |
void ActionShowModal() { | |
new Tela_exemplo_2Controller() | |
.setTitulo(tfTitulo.getText()) | |
.showModal(getWindow()); | |
} | |
@FXML | |
void ActionShowUndecorated() { | |
// new TelaExemploController() | |
// .setTitulo(tfTitulo.getText()) | |
// .showUndecorated(getWindow(), false); | |
new WindowController() { | |
@Override | |
public Region getRootPane() { | |
BorderPane pane = new BorderPane(); | |
pane.setPrefSize(300, 300); | |
MenuBar menu = new MenuBar(); | |
menu.getMenus().add(new Menu("Arquivo")); | |
menu.getMenus().add(new Menu("Editar")); | |
pane.setTop(menu); | |
StackPane paneCenter = new StackPane(); | |
paneCenter.setStyle("-fx-background-color: linear-gradient(aqua, blue);"); | |
pane.setCenter(paneCenter); | |
return pane; | |
} | |
@Override | |
public void initialize(URL location, ResourceBundle resources) { | |
} | |
}.show(getWindow()) | |
.altura(600) | |
.largura(800); | |
} | |
@FXML | |
void ActionShowUndecoratedTransparent() { | |
new TelaExemploController() | |
.setTitulo(tfTitulo.getText()) | |
.showUndecorated(getWindow(), true); | |
} | |
@FXML | |
private void Close() { | |
getWindow().close(); | |
} | |
@Override | |
public void onShow() { | |
} | |
} | |
// tela_exemplo.fxml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.geometry.Insets?> | |
<?import javafx.scene.control.Button?> | |
<?import javafx.scene.control.TextField?> | |
<?import javafx.scene.effect.DropShadow?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<?import javafx.scene.layout.StackPane?> | |
<StackPane xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"> | |
<children> | |
<AnchorPane id="AnchorPane" fx:id="pane" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: white; -fx-border-color: cyan;"> | |
<children> | |
<Button layoutX="31.0" layoutY="34.0" mnemonicParsing="false" onAction="#ActionShow" prefHeight="38.0" prefWidth="76.0" style="-fx-base: green;" text="show" /> | |
<Button layoutX="510.0" layoutY="360.0" mnemonicParsing="false" onAction="#Close" prefHeight="26.0" prefWidth="76.0" style="-fx-base: red;" text="Fechar" /> | |
<Button layoutX="121.0" layoutY="34.0" mnemonicParsing="false" onAction="#ActionShowModal" prefHeight="38.0" prefWidth="107.0" style="-fx-base: green;" text="showModal" /> | |
<Button layoutX="247.0" layoutY="34.0" mnemonicParsing="false" onAction="#ActionShowAsDialog" prefHeight="38.0" prefWidth="107.0" style="-fx-base: green;" text="showAsDialog" /> | |
<Button layoutX="31.0" layoutY="84.0" mnemonicParsing="false" onAction="#ActionShowUndecorated" prefHeight="38.0" prefWidth="328.0" style="-fx-base: green;" text="showUndecorated" /> | |
<Button layoutX="31.0" layoutY="134.0" mnemonicParsing="false" onAction="#ActionShowUndecoratedTransparent" prefHeight="38.0" prefWidth="328.0" style="-fx-base: green;" text="showUndecorated(transparent)" /> | |
<TextField fx:id="tfTitulo" layoutX="31.0" layoutY="188.0" prefHeight="25.0" prefWidth="328.0" promptText="Titulo da Janela" /> | |
</children> | |
<effect> | |
<DropShadow color="#00bfff" height="100.0" radius="49.5" width="100.0" /> | |
</effect> | |
</AnchorPane> | |
</children> | |
<padding> | |
<Insets bottom="50.0" left="50.0" right="50.0" top="50.0" /> | |
</padding> | |
</StackPane> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment