As the title says, I need to make a thin progress bar. I used this:
progressBar.setMaxHeight(0.1);
progressBar.setPrefHeight(0.1);
but that doesn't work. Does anyone have an idea?
You'll have to mess around with the styling to get it any smaller. I really recommend taking a look a the caspian.css that's included with Javafx - that's the default style sheet. It helps a lot when trying to override the look and feel of the default skins. Here's an example I put together that shows how it can be done:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ProgressBarTest extends Application {
public static void main(String[] args) { launch(args); }
#Override
public void start(final Stage stage) throws Exception {
//All the controls are added here
VBox box = new VBox();
box.getStylesheets().add("test.css");
ProgressBar pb = new ProgressBar(50);
box.getChildren().add(pb);
//Setting up your scene
Scene scene = new Scene(box);
stage.setScene(scene);
stage.show();
}
}
And here's the test.css I loaded up:
.progress-bar .bar {-fx-padding:1px; -fx-background-insets:0;}
And here is the output of the test app:
Related
I am trying to lose the white background on the webviewer
i have tried work around and other things but nothing seems to work
public static String url = "URL"; //lets say this has a transparent image on it (it does in my case)
public static Scene FrameWorks;
public static StackPane InnerFrame;
public static WebView viewer;
public static WebEngine webEngine;
public static void web() {
viewer = new WebView();
webEngine = viewer.getEngine();
webEngine.executeScript("document.width");
WebSite(url);
}
public static void WebSite(String URL) {
webEngine.executeScript("window.location = \""+URL+"\";");
}
public void start(Stage Level) {
web();
InnerFrame = new StackPane();
FrameWorks = new Scene(InnerFrame, 909, 609);
InnerFrame.getChildren().add(viewer);
FrameWorks.setFill(Color.TRANSPARENT);
InnerFrame.setStyle("-fx-background-color: rgba(255, 0, 0, 0);");
Level.setScene(FrameWorks);
Level.initStyle(StageStyle.TRANSPARENT);
Level.show();
}
I'm not sure that I fully understand your problem so correct me if I am wrong. Do you want everything other than the webview to be transparent? To more or less copy paste a comment from another post, on here I (we) want a Minimal, Complete, and Verifiable example demonstrating the problem. You should also remember to check if the question has already been asked and answered before asking your own question.
Now that I got that out of the way, here's an example where you can see the stack pane with a black background and the webview with a white background.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.layout.Background;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
WebView v = new WebView();
v.setOpacity(1); // 0 = fully transparent, 1 = fully visible.
v.setPrefWidth(100);
v.setMaxWidth(100);
v.setMaxHeight(100);
v.setPrefHeight(100);
v.setStyle("-fx-background-color:black;");
StackPane root = new StackPane();
root.getChildren().add(v);
root.setStyle("-fx-background-color:black;");
/*
* Remove the setStyle above, and use either one of these to only have the webview
* visible. root.setBackground(Background.EMPTY);
* root.setStyle("-fx-background-color:TRANSPARENT;");
*/
Scene scene = new Scene(root, 300, 250);
scene.setFill(Color.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.show();
}
}
If you remove the line:
root.setStyle("-fx-background-color:black;");
and replace it with either one of the lines that currently are in comments then you will now only see the webview:
/*
* Remove the setStyle above, and use either one of these to only have the webview
* visible.
* root.setBackground(Background.EMPTY);
* root.setStyle("-fx-background-color:TRANSPARENT;");
*/
And you can of course also set a transparency on the actual webview if you want to do that for some reason:
v.setOpacity(0); /*0.0 Fully Transparent - 1.0 Fully Visible*/
Please note that to do this I had to set the StageStyle to transparent, and unfortunately I'm not sure if it is possible to do it in any other way. Maybe someone else can put in comments if it is possible or not.
I hope this answers your question.
I am a little stumped on how to get started on this project I have in front of me. I simply need to create a calendar on a javafx stage for the current date with two simple next / prior buttons to go between months.
So far I have just created the minimum, a blank stage to appear.
public class Calendar extends Application{
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Java Calendar");
Pane base = new Pane();
Scene scene = new Scene(base, 500, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args){
Application.launch(args);
}
}
I had noticed under java documentation that there is a calendar class under java.util, however the documentation was rather confusing to me on how to implement it. Basically I want to ask, what is the best way to approach this? Would you be able to show me through the basics of how this or another Calendar class works? Or would I be best off using a grid pane, and switch between what scene is shown on the stage when I click the next or prior button?
Thank you so much for your time.
Try This
import java.time.LocalDate;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
VBox vbox = new VBox(20);
Scene scene = new Scene(vbox, 400, 400);
stage.setScene(scene);
DatePicker startDatePicker = new DatePicker();
DatePicker endDatePicker = new DatePicker();
startDatePicker.setValue(LocalDate.now());
endDatePicker.setValue(startDatePicker.getValue().plusDays(1));
vbox.getChildren().add(new Label("Start Date:"));
vbox.getChildren().add(startDatePicker);
vbox.getChildren().add(new Label("End Date:"));
vbox.getChildren().add(endDatePicker);
stage.show();
}
}
I have a simple application developed in javafx. The problem is that I want to remove the two tool bars but find no way how to do that. Here in the code I have set the visibility of the bottom toolbar to false.
For help if you need to answer: The id of the top toolbar is .top-toolbar while the id of the bottom toolbar is .bottom-toolbar. Your help will be appreciated greatly... Here is my code.
Thanks in advance.
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
public class PrivateHistory extends Application {
#Override
public void start(Stage stage) {
stage.setTitle("HTMLEditor Sample");
stage.setWidth(400);
stage.setHeight(300);
final HTMLEditor htmlEditor = new HTMLEditor();
htmlEditor.setPrefHeight(245);
Scene scene = new Scene(htmlEditor);
stage.setScene(scene);
Node node = htmlEditor.lookup(".bottom-toolbar");
node.setVisible(false);
//htmlEditor.setHtmlText("<img src='"+getClass().getResource("ball.png")+"' />");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
apply the following code on your htmlEditor
htmlEditor.lookup(".top-toolbar").setManaged(false);
htmlEditor.lookup(".top-toolbar").setVisible(false);
htmlEditor.lookup(".bottom-toolbar").setManaged(false);
htmlEditor.lookup(".bottom-toolbar").setVisible(false);
Here's my snippet:
package javafxdemo;
import org.tbee.javafx.scene.layout.MigPane;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class FXDemo extends Application {
#Override
public void start (Stage stage) throws Exception {
MigPane root = new MigPane();
Scene scene = new Scene(root);
Button b = new Button("Hello");
root.getChildren().add(b);
stage.setScene(scene);
stage.setTitle("FX");
stage.show();
}
public static void main (String[] args) {
launch (args);
}
}
When running the gui doesn't show properly: the frame size is smaller than the button. Why does it happens? In HBox Layout when setting the scene it is automatically resized, so why with MiGLayout it doesn't work?
I'm using MigLayout 4.3
So, I filed an issue and later found out a workaround for this:
just add stage.sizeToScene() after stage.show().
This question already has an answer here:
JavaFX: Undecorated Window
(1 answer)
Closed 8 years ago.
I am making JavaFX destop application. I want to remove the default windows border and also I want to customize the 3 standard icons of minimize , maximize and close.
The original motivation of this kind of looks or customization is new Kaspersky 2012 User Interface.... I want to design something like that... :)
This example might be a good starting point. All window decoration is removed. A class extending HBox can be used to place custom buttons for standard window operations.
package javafxdemo;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class JavaDemo extends Application {
public static void main(String[] args) {
launch(args);
}
class WindowButtons extends HBox {
public WindowButtons() {
Button closeBtn = new Button("X");
closeBtn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent actionEvent) {
Platform.exit();
}
});
this.getChildren().add(closeBtn);
}
}
#Override
public void start(Stage primaryStage) {
//remove window decoration
primaryStage.initStyle(StageStyle.UNDECORATED);
BorderPane borderPane = new BorderPane();
borderPane.setStyle("-fx-background-color: green;");
ToolBar toolBar = new ToolBar();
int height = 25;
toolBar.setPrefHeight(height);
toolBar.setMinHeight(height);
toolBar.setMaxHeight(height);
toolBar.getItems().add(new WindowButtons());
borderPane.setTop(toolBar);
primaryStage.setScene(new Scene(borderPane, 300, 250));
primaryStage.show();
}
}
You can also download the JavaFX Samples where you can find many more useful examples.