JFXDecorator使用问题:修改边框颜色及移除窗口缩放按钮
Hey there! Let's work through those two JFXDecorator issues you've run into—they're both easy fixes with the right methods and CSS tweaks.
JFXDecorator relies on CSS for its styling, so you can override the default black border either with inline styles or an external CSS file (the latter is better for maintainability if you have multiple style changes down the line).
Option 1: Inline Style (Quick Fix)
Add this line right after initializing your decorator to set the border color and width directly in code:
decorator.setStyle("-fx-border-color: #2196F3; -fx-border-width: 2px;");
Replace #2196F3 with any hex color code, RGB value, or named color you prefer (e.g., red, rgb(76, 175, 80)).
Option 2: External CSS File (Recommended)
Create a CSS file (e.g., decorator-styles.css) with this rule:
.jfx-decorator { -fx-border-color: #4CAF50; /* Your desired border color */ -fx-border-width: 1.5px; /* Adjust border thickness as needed */ }
Then link the CSS file to your decorator:
decorator.getStylesheets().add(getClass().getResource("/path/to/decorator-styles.css").toExternalForm());
The setCustomMaximize(false) method you're using only disables the custom maximize behavior—it doesn't hide the button itself. To fully remove the zoom button, use the setMaximizeButtonVisible() method:
decorator.setMaximizeButtonVisible(false);
If you ever need to hide the minimize button too, you can use:
decorator.setMinimizeButtonVisible(false);
Updated Full Code Example
Here's how your start method would look with both fixes applied:
public void start(Stage primaryStage){ JFXDecorator decorator = new JFXDecorator(primaryStage, gridContainer); decorator.setCustomMaximize(false); decorator.setText("Window Title"); // Fix 1: Change border color decorator.setStyle("-fx-border-color: #2196F3; -fx-border-width: 2px;"); // Fix 2: Hide zoom/maximize button decorator.setMaximizeButtonVisible(false); Scene scene = new Scene(decorator); primaryStage.setScene(scene); primaryStage.show(); }
内容的提问来源于stack exchange,提问作者Melowski

