StageStyle.DECORATED
最小化または最大化ボタンがなく、閉じるボタンの元の外観でステージを作成する方法を見つけようとしていました。私は試してみましたStageStyle.UTILITY
が、それはかなり奇妙に見えます。
このようなウィンドウが欲しいのですが:(これはintelliJのウィンドウです)IntelliJURLウィンドウを開く
誰かがこれについていくつかの考えを持っていますか?ありがとう!
ステージまたはダイアログのデフォルトのStageStyleは次StageStyle.DECORATED
のとおりです。StageStyleドキュメントを読むと、次のように表示されます。
したがって、上記の説明から、ステージにいくつかの違いが見られる理由は、「最小限のプラットフォーム装飾」です。もちろん、これは、ユーザーまたはクライアントが使用しているプラットフォームによっては、目立たない場合や、気付かない場合があります。私の知る限り、オペレーティングシステムは、アプリケーションのタイトルバーと境界線の表示方法を担当しているため、その装飾にアクセスしたり変更したりする方法はありません。それを達成できると私が知っている唯一の方法は、独自のカスタムステージを作成し、必要なCSSを適用することです。これを行うには、を設定StageStyle.UNDECORATED
し、タイトルバーを最初から作成する必要があります。
特定のケースでは、ステージを使用する必要はありませんが。最小化ボタンと最大化ボタンがないカスタムダイアログを使用してこれを実現できます(少なくともJava 8では、最新バージョンでも同じだと思います)。ここに例を示します。
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) throws Exception {
String input = showInputDialog();
System.out.println("User Input : " + input);
Platform.exit();
}
private String showInputDialog() {
// Create the custom dialog.
Dialog<String> dialog = new Dialog<String>();
dialog.setTitle("Open URL");
// Remove the header
dialog.setHeaderText(null);
// If you want to add an icon to the Dialog
// dialog.setGraphic(new
// ImageView(this.getClass().getResource("logo.png").toExternalForm()));
// Set the button types.
ButtonType okButtonType = new ButtonType("OK", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(okButtonType, ButtonType.CANCEL);
// Create a VBox to store your controls
VBox mainPane = new VBox(5);
Label promptLabel = new Label("Specify URL :");
HBox urlPane = new HBox();
urlPane.setPadding(new Insets(5));
urlPane.setAlignment(Pos.CENTER);
TextField urlField = new TextField();
Button searchButton = new Button("Search");
searchButton.setOnAction(e->{
// open a FileChooser etc and do something
});
urlPane.getChildren().addAll(urlField, searchButton);
mainPane.getChildren().addAll(promptLabel, urlField);
HBox.setHgrow(urlField, Priority.ALWAYS);
// Enable/Disable OK button depending on whether a urlField was filled.
Node confirmationButton = dialog.getDialogPane().lookupButton(okButtonType);
confirmationButton.disableProperty().bind(urlField.textProperty().isEmpty());
// set the content of the Dialog
dialog.getDialogPane().setContent(mainPane);
// set dialog return value
dialog.setResultConverter(dialogButton -> {
if (dialogButton == okButtonType) {
return urlField.getText();
}
return null;
});
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
return result.get();
} else {
return null;
}
}
public static void main(String[] args) {
launch(args);
}
}
結果 :
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加