2_jfoenix_设置图标,JFXDialog,JFXTabPane

原文链接: https://juejin.im/post/5ce522cb5188252db9306f30

1_设置图标


resource

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("电源");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.getIcons().add(new Image("sample/resource/power.png"));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
复制代码

2_JFXDialog


package sample;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog;
import com.jfoenix.controls.JFXDialogLayout;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;

public class Controller {
    public JFXButton button;
    @FXML
    private StackPane layout;

    public void buttonaction(ActionEvent event){
        JFXDialogLayout messge=new JFXDialogLayout();
        messge.setHeading(new Text("成功"));
        messge.setBody(new Text(
                "恭喜成功\n"+"对话框\n"+"莫狄掘金"));
        JFXDialog mag=new JFXDialog(layout,messge,JFXDialog.DialogTransition.CENTER);

        JFXButton button1=new JFXButton("close");
        button1.setOnAction(new EventHandler() {
            @Override
            public void handle(ActionEvent event) {
                mag.close();
            }
        });
        messge.setActions(button1);

        mag.show();

    }
}
复制代码

3_JFXTabPane


.tab{
    -fx-pref-width: 160;
    -fx-pref-height: 60;
}

.tab-header-background{
    -fx-background-color: #282828;
}

.jfx-tab-pane .tab-selected-line {
    -fx-background-color: #33ffff;
}
复制代码

3.1_垂直带有图标的JFXTabPane

package sample;

import com.jfoenix.controls.JFXTabPane;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.TextAlignment;

public class Controller {

    @FXML
    private JFXTabPane tabContainer;

    @FXML
    private Tab U1;

    @FXML
    private Tab U2;

    @FXML
    private Tab U3;

    private double tabWidth = 90.0;

    @FXML
    public void initialize() {
        configureView();
    }

    private void configureView() {
        tabContainer.setTabMinWidth(tabWidth);
        tabContainer.setTabMaxWidth(tabWidth);
        tabContainer.setTabMinHeight(tabWidth);
        tabContainer.setTabMaxHeight(tabWidth);
        tabContainer.setRotateGraphic(true);

        configureTab(U1, "莫狄", "sample/resources/logout.png");
        configureTab(U2, "掘金\n博客", "sample/resources/settings.png");
        configureTab(U3, "视频", "sample/resources/user-profile.png");

    }

    private void configureTab(Tab tab, String title, String iconPath) {
        double imageWidth = 40.0;

        ImageView imageView = new ImageView(new Image(iconPath));
        imageView.setFitHeight(imageWidth);
        imageView.setFitWidth(imageWidth);

        Label label = new Label(title);
        label.setMaxWidth(tabWidth - 20);
        label.setTextAlignment(TextAlignment.CENTER);

        BorderPane tabPane = new BorderPane();
        tabPane.setRotate(90.0);
        tabPane.setMaxWidth(tabWidth);
        tabPane.setCenter(imageView);
        tabPane.setBottom(label);

        tab.setText("");
        tab.setGraphic(tabPane);
    }

}
复制代码

.tab-header-background{
    -fx-background-color: #282828;
}

.jfx-tab-pane .tab-selected-line {
    -fx-background-color: #282828;
}

.tab:selected
{
    -fx-background-color: #26282C;
    -fx-background-radius: 0;
    -fx-background-insets: 0;
    -fx-border-width: 2 0 0 0;
    -fx-border-color: #33ffff;

}
复制代码

转载于:https://juejin.im/post/5ce522cb5188252db9306f30

你可能感兴趣的:(2_jfoenix_设置图标,JFXDialog,JFXTabPane)