Created
June 9, 2021 10:03
-
-
Save Da9el00/d5f854781e27cefa72d12b053a9952dd to your computer and use it in GitHub Desktop.
JavaFX Design - Modern Login Screen
This file contains hidden or 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
/*Color gradient*/ | |
.colorBackground{ | |
-fx-background-color: linear-gradient( to right top,#facd68, #fc76b3); | |
} |
This file contains hidden or 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
package sample; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.layout.AnchorPane; | |
import javafx.stage.Stage; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
public class Controller implements Initializable { | |
private double x = 0,y = 0; | |
@FXML | |
private AnchorPane sideBar; | |
private Stage stage; | |
@Override | |
public void initialize(URL url, ResourceBundle resourceBundle) { | |
sideBar.setOnMousePressed(mouseEvent -> { | |
x = mouseEvent.getSceneX(); | |
y = mouseEvent.getSceneY(); | |
}); | |
sideBar.setOnMouseDragged(mouseEvent -> { | |
stage.setX(mouseEvent.getScreenX() - x); | |
stage.setY(mouseEvent.getScreenY() - y); | |
}); | |
} | |
public void setStage(Stage stage){ | |
this.stage = stage; | |
} | |
@FXML | |
void closeProgram(ActionEvent event) { | |
stage.close(); | |
} | |
} |
This file contains hidden or 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
package sample; | |
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 Main extends Application { | |
@Override | |
public void start(Stage primaryStage) throws Exception{ | |
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml")); | |
Parent root = loader.load(); | |
Controller controller = loader.getController(); | |
Scene scene = new Scene(root); | |
scene.setFill(Color.TRANSPARENT); | |
primaryStage.initStyle(StageStyle.TRANSPARENT); | |
primaryStage.setScene(scene); | |
controller.setStage(primaryStage); | |
primaryStage.show(); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<?import com.jfoenix.controls.JFXButton?> | |
<?import com.jfoenix.controls.JFXTextField?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<?import javafx.scene.paint.Color?> | |
<?import javafx.scene.paint.LinearGradient?> | |
<?import javafx.scene.paint.Stop?> | |
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: transparent;" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"> | |
<children> | |
<AnchorPane layoutX="224.0" layoutY="76.0" prefHeight="249.0" prefWidth="310.0" style="-fx-background-radius: 25; -fx-background-color: white;"> | |
<children> | |
<JFXTextField layoutX="72.0" layoutY="53.0" prefHeight="25.0" prefWidth="174.0" promptText="Enter Login"> | |
<focusColor> | |
<LinearGradient endX="1.0" endY="1.0"> | |
<stops> | |
<Stop> | |
<color> | |
<Color red="0.9803921580314636" green="0.8039215803146362" blue="0.40784314274787903" /> | |
</color> | |
</Stop> | |
<Stop offset="1.0"> | |
<color> | |
<Color red="0.9882352948188782" green="0.4627451002597809" blue="0.7019608020782471" /> | |
</color> | |
</Stop> | |
</stops> | |
</LinearGradient> | |
</focusColor> | |
</JFXTextField> | |
<JFXTextField layoutX="72.0" layoutY="109.0" prefHeight="25.0" prefWidth="174.0" promptText="Enter Password"> | |
<focusColor> | |
<LinearGradient endX="1.0" endY="1.0"> | |
<stops> | |
<Stop> | |
<color> | |
<Color red="0.9803921580314636" green="0.8039215803146362" blue="0.40784314274787903" /> | |
</color> | |
</Stop> | |
<Stop offset="1.0"> | |
<color> | |
<Color red="0.9882352948188782" green="0.4627451002597809" blue="0.7019608020782471" /> | |
</color> | |
</Stop> | |
</stops> | |
</LinearGradient> | |
</focusColor> | |
</JFXTextField> | |
<JFXButton buttonType="RAISED" layoutX="112.0" layoutY="176.0" prefHeight="41.0" prefWidth="87.0" styleClass="colorBackground" stylesheets="@color.css" text="Login" /> | |
</children> | |
</AnchorPane> | |
<AnchorPane fx:id="sideBar" layoutX="31.0" layoutY="53.0" prefHeight="295.0" prefWidth="220.0" style="-fx-background-radius: 25;" styleClass="colorBackground" stylesheets="@color.css"> | |
<children> | |
<JFXButton layoutX="182.0" layoutY="14.0" onAction="#closeProgram" text="X" /> | |
</children> | |
</AnchorPane> | |
</children> | |
</AnchorPane> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment