I want to remove top and bottom border of Borderpane.
I am using the following css but its removing all the borders.
.borderpane-container {
-fx-background-color: #ffffff;
-fx-box-border: #ffffff;
}
Is there a way to only remove top and bottom border ?
Well setting -fx-border-width works fine with me. Here is a small example :
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class BorderExample extends Application {
#Override
public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
pane.setCenter(new Label("Hello there"));
pane.setStyle("-fx-border-color : black; -fx-border-width : 0 5 ");
stage.setScene(new Scene(pane,200,200));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Of course you can do the same loading an external css file from resources like
#myPane{
-fx-border-color : black;
-fx-border-width : 0 5;
}
In case I didn't understand you correctly let me know.
Related
I need a window that can be move up down in my main window. Mainly IDE(IntelliJ, CodeBlock, Netbeans etc) output window feature.
I use TitledPane. By using this I can give a height that is expanded when I click the pane, but I can't expand the pane in any height.
see this - not expanded:
and this- expanded:
My code is here
Try using SplitPane. I guess this is what you want. You can learn more from the following link
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/SplitPane.html
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
SplitPane splitPane = new SplitPane(new Pane(), new Pane());
splitPane.setDividerPositions(0.5);
splitPane.setOrientation(Orientation.VERTICAL);
primaryStage.setScene(new Scene(splitPane,400,400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
In HTMLEditor of JavaFX: the preview color is so small.
I want to show bigger like picture below:
How i can do.
Thanks
The style of the HTMLEditor is customized via CSS.
.html-editor-foreground {
-fx-color-rect-width: 16;
-fx-color-rect-height: 16;
-fx-graphic: null;
}
Here we style the foreground color picker picked color indicator as a (relatively) large rectangle (with a pink color chosen for the sample):
Sample Code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
public class EditorSample extends Application {
#Override
public void start(Stage stage) throws Exception {
HTMLEditor editor = new HTMLEditor();
Scene scene = new Scene(editor);
scene.getStylesheets().add(
this.getClass().getResource(
"html-editor-large-color-rect.css"
).toExternalForm()
);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Consider this sample program which is adding a TabPane into an Alert. As you will see, there is a white padding on the left of the TabPane that I just cannot remove.
If anyone has any idea it will be great.
Code:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class AlertTest extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new HBox());
primaryStage.setScene(scene);
primaryStage.show();
Alert alert = new Alert(Alert.AlertType.NONE);
alert.setTitle("");
alert.initOwner(primaryStage);
TabPane tabPane = new TabPane(new Tab("test"));
tabPane.setPadding(Insets.EMPTY);
alert.getDialogPane().setPadding(Insets.EMPTY);
alert.getDialogPane().setContent(tabPane);
alert.show();
}
}
Visual :
If you add css like this:
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new HBox());
primaryStage.setScene(scene);
//add this 3 lines
String css = Main.class.getResource("styles.css").toExternalForm();
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
...
}
and in styles.css add
.dialog-pane:no-header .graphic-container {
-fx-padding: 0; /* 10px 0px 0px 10px */
}
You can find more info about the default styles in file: fxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.css
and here is the result and full code demo:
I'm making a Mario themed application, and I would like the buttons to have the effect that when the user hovers over it with his/her mouse, a mushroom (image) appears next to the text of the button, and disappears when the mouse moves away.I'm trying to do this using css.
How can one do this?
Use the hover pseudoclasses.
.button:hover{
-fx-graphic: url('your_path_to_image');
}
Complete Example
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage primaryStage) {
Button button = new Button("Click");
HBox container = new HBox(button);
container.setAlignment(Pos.CENTER);
Scene scene = new Scene(container, 200, 200);
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
style.css
.button:hover{
-fx-graphic: url('http://files.softicons.com/download/game-icons/super-mario-icons-by-sandro-pereira/png/16/Mushroom%20-%201UP.png');
}
Image
On hover
I want to put a background image into a scene but I always get an error message
PM com.sun.javafx.css.parser.CSSParser parse and
WARNING: CSS Error parsing file:/D:/Login/bin/login/Login.css: Expected LBRACE at [1,9]
Here is a SSCE from my Login.java:
package login;
import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Login extends Application {
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
Scene scene = new Scene(grid, 300, 275);
scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And here is my a CSS from my Login.css
#CHARSET "ISO-8859-1";
.root {
-fx-background-image: url("background.jpg");
}
Does it have to do with my current plugin? I use eclipse Luna and the WTP toolkit to work with style sheets.
Many thanks!
The CSS parser in recent JavaFX versions seems to choke on the #CHARSET declarations. If you remove that declaration, it should fix the problem.