下面列出了怎么用javafx.scene.control.ProgressBar的API类实例代码及写法,或者点击链接到github查看源代码。
private Scene createPreloaderScene() {
bar = new ProgressBar();
//BorderPane p = new BorderPane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("updater.fxml"));
AnchorPane p = null;
try {
p = loader.load();
} catch (IOException ex) {
Logger.getLogger(MainApp_Controller.class.getName()).log(Level.SEVERE, null, ex);
}
//at this point this class has done enough, and we need to contact with the
//appropriate controllers.
controller = loader.<UpdaterController>getController();
Scene pr = new Scene(p);
pr.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
return pr;
}
private Scene createPreloaderScene() {
bar = new ProgressBar();
//BorderPane p = new BorderPane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("loading.fxml"));
AnchorPane p = null;
try {
p = loader.load();
} catch (IOException ex) {
Logger.getLogger(MainApp_Controller.class.getName()).log(Level.SEVERE, null, ex);
}
//at this point this class has done enough, and we need to contact with the
//appropriate controllers.
controller = loader.<Loading_Controller>getController();
Scene pr = new Scene(p);
pr.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
return pr;
}
/**
* Create the loading pane.
*/
public LoadingPane() {
setAlignment(Pos.CENTER);
VBox content = new VBox();
content.setAlignment(Pos.CENTER);
Text text = new Text(LabelGrabber.INSTANCE.getLabel("loading.text") + "...");
text.setStyle(" -fx-font: bold italic 20pt \"Arial\";");
FadeTransition textTransition = new FadeTransition(Duration.seconds(1.5), text);
textTransition.setAutoReverse(true);
textTransition.setFromValue(0);
textTransition.setToValue(1);
textTransition.setCycleCount(Transition.INDEFINITE);
textTransition.play();
content.getChildren().add(text);
bar = new ProgressBar();
content.getChildren().add(bar);
getChildren().add(content);
setOpacity(0);
setStyle("-fx-background-color: #555555;");
setVisible(false);
}
/**
* Create a new status panel.
* <p/>
* @param group the group this panel is part of.
* @param labelText the text to put on the label on this panel.
* @param index the index of this panel on the group.
*/
StatusPanel(StatusPanelGroup group, String labelText, int index) {
setAlignment(Pos.CENTER);
setSpacing(5);
this.group = group;
this.index = index;
label = new Label(labelText);
label.setAlignment(Pos.CENTER);
label.setMaxHeight(Double.MAX_VALUE);
HBox.setMargin(label, new Insets(5));
progressBar = new ProgressBar();
progressBar.setMaxWidth(Double.MAX_VALUE); //Allow progress bar to fill space.
HBox.setHgrow(progressBar, Priority.ALWAYS);
cancelButton = new Button("", new ImageView(new Image("file:icons/cross.png", 13, 13, false, true)));
Utils.setToolbarButtonStyle(cancelButton);
cancelButton.setAlignment(Pos.CENTER);
getChildren().add(label);
getChildren().add(progressBar);
getChildren().add(cancelButton);
}
public NotificationBarPane(Node content) {
super(content);
progressBar = new ProgressBar();
label = new Label("infobar!");
bar = new HBox(label);
bar.setMinHeight(0.0);
bar.getStyleClass().add("info-bar");
bar.setFillHeight(true);
setBottom(bar);
// Figure out the height of the bar based on the CSS. Must wait until after we've been added to the parent node.
sceneProperty().addListener(o -> {
if (getParent() == null) return;
getParent().applyCss();
getParent().layout();
barHeight = bar.getHeight();
bar.setPrefHeight(0.0);
});
items = FXCollections.observableArrayList();
items.addListener((ListChangeListener<? super Item>) change -> {
config();
showOrHide();
});
}
@Test
public void getText() {
ProgressBar progressBar = (ProgressBar) getPrimaryStage().getScene().getRoot().lookup(".progress-bar");
LoggingRecorder lr = new LoggingRecorder();
List<String> text = new ArrayList<>();
Platform.runLater(() -> {
RFXProgressBar rfxProgressBar = new RFXProgressBar(progressBar, null, null, lr);
progressBar.setProgress(0.56);
rfxProgressBar.mouseReleased(null);
text.add(rfxProgressBar.getAttribute("text"));
});
new Wait("Waiting for progress bar text.") {
@Override
public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("0.56", text.get(0));
}
@Override
protected void commonCanDoFixture() {
final SystemUtils utils = Mockito.mock(SystemUtils.class);
Mockito.when(utils.getPathTemplatesDirUser()).thenReturn("");
SystemUtils.setSingleton(utils);
ui = Mockito.mock(JfxUI.class);
statusWidget = Mockito.mock(Label.class);
progressBar = Mockito.mock(ProgressBar.class);
mainstage = Mockito.mock(Stage.class);
file = Mockito.mock(File.class);
modifiedAlert = Mockito.mock(Alert.class);
openSaveManager = Mockito.mock(OpenSaver.class);
fileChooser = Mockito.mock(FileChooser.class);
currentFolder = Optional.empty();
cmd = new NewDrawing(file, openSaveManager, progressBar, statusWidget, ui, fileChooser, currentFolder, mainstage, modifiedAlert);
}
public NotificationBarPane (Node content) {
super(content);
progressBar = new ProgressBar();
label = new Label("infobar!");
bar = new HBox(label);
bar.setMinHeight(0.0);
bar.getStyleClass().add("info-bar");
bar.setFillHeight(true);
setBottom(bar);
// Figure out the height of the bar based on the CSS. Must wait until after we've been added to the parent node.
sceneProperty().addListener(o -> {
if (getParent() == null) {
return;
}
getParent().applyCss();
getParent().layout();
barHeight = bar.getHeight();
bar.setPrefHeight(0.0);
});
items = FXCollections.observableArrayList();
items.addListener((ListChangeListener<? super Item>) change -> {
config();
showOrHide();
});
}
@Override
protected void commonCanDoFixture() {
final SystemUtils utils = Mockito.mock(SystemUtils.class);
Mockito.when(utils.getPathTemplatesDirUser()).thenReturn("");
SystemUtils.setSingleton(utils);
ui = Mockito.mock(JfxUI.class);
statusWidget = Mockito.mock(Label.class);
progressBar = Mockito.mock(ProgressBar.class);
mainstage = Mockito.mock(Stage.class);
file = Mockito.mock(File.class);
modifiedAlert = Mockito.mock(Alert.class);
openSaveManager = Mockito.mock(OpenSaver.class);
fileChooser = Mockito.mock(FileChooser.class);
currentFolder = Optional.empty();
injector = Mockito.mock(Injector.class);
prefService = Mockito.mock(PreferencesService.class);
Mockito.when(injector.getInstance(PreferencesService.class)).thenReturn(prefService);
cmd = new SaveDrawing(true, true, currentFolder, fileChooser, injector,
file, openSaveManager, progressBar, ui, statusWidget, mainstage, modifiedAlert);
}
@Override
protected void commonCanDoFixture() {
final SystemUtils utils = Mockito.mock(SystemUtils.class);
Mockito.when(utils.getPathTemplatesDirUser()).thenReturn("");
SystemUtils.setSingleton(utils);
ui = Mockito.mock(JfxUI.class);
statusWidget = Mockito.mock(Label.class);
progressBar = Mockito.mock(ProgressBar.class);
mainstage = Mockito.mock(Stage.class);
file = Mockito.mock(File.class);
modifiedAlert = Mockito.mock(Alert.class);
openSaveManager = Mockito.mock(OpenSaver.class);
fileChooser = Mockito.mock(FileChooser.class);
currentFolder = Optional.empty();
cmd = new LoadDrawing(file, openSaveManager, progressBar, statusWidget, ui, fileChooser, currentFolder, mainstage, modifiedAlert);
}
public NotificationBarPane(Node content) {
super(content);
progressBar = new ProgressBar();
label = new Label("infobar!");
bar = new HBox(label);
bar.setMinHeight(0.0);
bar.getStyleClass().add("info-bar");
bar.setFillHeight(true);
setBottom(bar);
// Figure out the height of the bar based on the CSS. Must wait until after we've been added to the parent node.
sceneProperty().addListener(o -> {
if (getParent() == null) return;
getParent().applyCss();
getParent().layout();
barHeight = bar.getHeight();
bar.setPrefHeight(0.0);
});
items = FXCollections.observableArrayList();
items.addListener((ListChangeListener<? super Item>) change -> {
config();
showOrHide();
});
}
public NotificationBarPane(Node content) {
super(content);
progressBar = new ProgressBar();
label = new Label("infobar!");
bar = new HBox(label);
bar.setMinHeight(0.0);
bar.getStyleClass().add("info-bar");
bar.setFillHeight(true);
setBottom(bar);
// Figure out the height of the bar based on the CSS. Must wait until after we've been added to the parent node.
sceneProperty().addListener(o -> {
if (getParent() == null) return;
getParent().applyCss();
getParent().layout();
barHeight = bar.getHeight();
bar.setPrefHeight(0.0);
});
items = FXCollections.observableArrayList();
items.addListener((ListChangeListener<? super Item>) change -> {
config();
showOrHide();
});
}
private Parent createContent() {
VBox root = new VBox();
root.setPrefSize(400, 600);
TextField fieldURL = new TextField();
root.getChildren().addAll(fieldURL);
fieldURL.setOnAction(event -> {
Task<Void> task = new DownloadTask(fieldURL.getText());
ProgressBar progressBar = new ProgressBar();
progressBar.setPrefWidth(350);
progressBar.progressProperty().bind(task.progressProperty());
root.getChildren().add(progressBar);
fieldURL.clear();
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
});
return root;
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
exporter = injector.getInstance(Exporter.class);
hand.setActivated(true);
when(pencil.isActivated()).thenReturn(false);
WaitForAsyncUtils.waitForFxEvents();
final TemplateManager template = injector.getInstance(TemplateManager.class);
template.templatePane = new FlowPane();
final StatusBarController status = injector.getInstance(StatusBarController.class);
Mockito.when(status.getLabel()).thenReturn(new Label());
Mockito.when(status.getProgressBar()).thenReturn(new ProgressBar());
chooser = Mockito.mock(FileChooser.class);
Mockito.when(chooser.getExtensionFilters()).thenReturn(FXCollections.observableArrayList());
Mockito.when(chooser.showOpenDialog(Mockito.any())).thenReturn(tmp.newFile());
Mockito.when(chooser.showSaveDialog(Mockito.any())).thenReturn(tmp.newFile());
final Field field = Exporter.class.getDeclaredField("fileChooserExport");
field.setAccessible(true);
field.set(exporter, chooser);
}
private void addProgessBar() {
// Add progress bar
progressBar = new ProgressBar();
progressBar.setProgress(0.25);
// progressBar.setetStringPainted(true);
// Border border =
// BorderFactory.createTitledBorder("Processing... <Press \"ESC\" to cancel> ");
// progressBar.setBorder(border);
dialog.mainPane.setTop(progressBar);
// this.dialog.repaint();
progressBar.setVisible(true);
// this.dialog.pack();
}
public ModalCancellableStage(String displayText) {
initModality(Modality.APPLICATION_MODAL);
initStyle(StageStyle.UNDECORATED);
setOnShowing((event) -> {
centerOnScreen();
cancel = false;
});
StackPane root = new StackPane();
VBox items = new VBox(10);
Label label = new Label(displayText);
label.setAlignment(Pos.CENTER);
items.getChildren().add(label);
StackPane barPane = new StackPane();
ProgressBar bar = new ProgressBar();
bar.setMaxWidth(Double.MAX_VALUE);
bar.prefWidthProperty().bind(widthProperty().subtract(50));
StackPane.setAlignment(bar, Pos.CENTER);
barPane.getChildren().add(bar);
barPane.setAlignment(Pos.CENTER);
items.getChildren().add(barPane);
StackPane buttonPane = new StackPane();
Button cancelButton = new Button(LabelGrabber.INSTANCE.getLabel("cancel.text"));
StackPane.setAlignment(buttonPane, Pos.CENTER);
buttonPane.setAlignment(Pos.CENTER);
buttonPane.getChildren().add(cancelButton);
cancelButton.setAlignment(Pos.CENTER);
cancelButton.setOnAction((event) -> {
cancel = true;
hide();
cancellable.cancelOp();
});
items.getChildren().add(buttonPane);
StackPane.setMargin(items, new Insets(10));
root.getChildren().add(items);
Scene scene = new Scene(root);
if (QueleaProperties.get().getUseDarkTheme()) {
scene.getStylesheets().add("org/modena_dark.css");
}
setScene(scene);
}
private void nextPane(Service<Rectangle> recBuilder) {
loading[counter].textProperty().bind(recBuilder.messageProperty());
indicators[counter].visibleProperty().bind(
recBuilder.progressProperty().isNotEqualTo(
new SimpleDoubleProperty(
ProgressBar.INDETERMINATE_PROGRESS)));
recBuilder.restart();
}
public void initializeAction() {
dc.closeAdBtn.setVisible(false);
dc.webView.getEngine().load(adUrl);
dc.webView.getEngine().locationProperty().addListener((ObservableValue<? extends String> ov, final String oldLoc, final String loc) -> {
if (!adUrl.equals(loc)) {
Platform.runLater(() -> {
ApplicationStageManager.getApplication().getHostServices().showDocument(loc);
});
}
dc.webView.getEngine().load(adUrl);
});
DialogUtil.setCloseAdBtn(dc.closeAdBtn);
dc.progressBar.setProgress(ProgressBar.INDETERMINATE_PROGRESS);
}
public ProgressBarSample() {
super(400,100);
double y = 15;
final double SPACING = 15;
ProgressBar p1 = new ProgressBar();
p1.setLayoutY(y);
y += SPACING;
ProgressBar p2 = new ProgressBar();
p2.setPrefWidth(150);
p2.setLayoutY(y);
y += SPACING;
ProgressBar p3 = new ProgressBar();
p3.setPrefWidth(200);
p3.setLayoutY(y);
y = 15;
ProgressBar p4 = new ProgressBar();
p4.setLayoutX(215);
p4.setLayoutY(y);
p4.setProgress(0.25);
y += SPACING;
ProgressBar p5 = new ProgressBar();
p5.setPrefWidth(150);
p5.setLayoutX(215);
p5.setLayoutY(y);
p5.setProgress(0.50);
y += SPACING;
ProgressBar p6 = new ProgressBar();
p6.setPrefWidth(200);
p6.setLayoutX(215);
p6.setLayoutY(y);
p6.setProgress(1);
getChildren().addAll(p1,p2,p3,p4,p5,p6);
}
private void showSplash(final Stage initStage, final Task<Void> task) {
final ProgressBar loadProgress = new ProgressBar();
loadProgress.progressProperty().bind(task.progressProperty());
final Pane splashLayout = new VBox();
final Image img = new Image("res/LaTeXDrawSmall.png", 450, 250, true, true); //NON-NLS
final ImageView splash = new ImageView(img);
splashLayout.getChildren().addAll(splash, loadProgress);
splashLayout.setEffect(new DropShadow());
loadProgress.setPrefWidth(img.getWidth());
task.setOnSucceeded(ignore -> {
loadProgress.progressProperty().unbind();
loadProgress.setProgress(1d);
final FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.8), splashLayout);
fadeSplash.setFromValue(1d);
fadeSplash.setToValue(0d);
fadeSplash.setOnFinished(evt -> {
initStage.hide();
mainStage.setIconified(false);
mainStage.toFront();
});
fadeSplash.play();
});
final Scene splashScene = new Scene(splashLayout);
initStage.setScene(splashScene);
initStage.initStyle(StageStyle.UNDECORATED);
initStage.getIcons().add(new Image("/res/LaTeXDrawIcon.png")); //NON-NLS
initStage.centerOnScreen();
initStage.toFront();
initStage.show();
}
public static void reset() {
add(Node.class, JavaFXElement.class);
add(TextInputControl.class, JavaFXTextInputControlElement.class);
add(HTMLEditor.class, JavaFXHTMLEditor.class);
add(CheckBox.class, JavaFXCheckBoxElement.class);
add(ToggleButton.class, JavaFXToggleButtonElement.class);
add(Slider.class, JavaFXSliderElement.class);
add(Spinner.class, JavaFXSpinnerElement.class);
add(SplitPane.class, JavaFXSplitPaneElement.class);
add(ProgressBar.class, JavaFXProgressBarElement.class);
add(ChoiceBox.class, JavaFXChoiceBoxElement.class);
add(ColorPicker.class, JavaFXColorPickerElement.class);
add(ComboBox.class, JavaFXComboBoxElement.class);
add(DatePicker.class, JavaFXDatePickerElement.class);
add(TabPane.class, JavaFXTabPaneElement.class);
add(ListView.class, JavaFXListViewElement.class);
add(TreeView.class, JavaFXTreeViewElement.class);
add(TableView.class, JavaFXTableViewElement.class);
add(TreeTableView.class, JavaFXTreeTableViewElement.class);
add(CheckBoxListCell.class, JavaFXCheckBoxListCellElement.class);
add(ChoiceBoxListCell.class, JavaFXChoiceBoxCellElement.class);
add(ComboBoxListCell.class, JavaFXComboBoxCellElement.class);
add(CheckBoxTreeCell.class, JavaFXCheckBoxTreeCellElement.class);
add(ChoiceBoxTreeCell.class, JavaFXChoiceBoxCellElement.class);
add(ComboBoxTreeCell.class, JavaFXComboBoxCellElement.class);
add(TableCell.class, JavaFXTableViewCellElement.class);
add(CheckBoxTableCell.class, JavaFXCheckBoxTableCellElement.class);
add(ChoiceBoxTableCell.class, JavaFXChoiceBoxCellElement.class);
add(ComboBoxTableCell.class, JavaFXComboBoxCellElement.class);
add(TreeTableCell.class, JavaFXTreeTableCellElement.class);
add(CheckBoxTreeTableCell.class, JavaFXCheckBoxTreeTableCell.class);
add(ChoiceBoxTreeTableCell.class, JavaFXChoiceBoxCellElement.class);
add(ComboBoxTreeTableCell.class, JavaFXComboBoxCellElement.class);
add(WebView.class, JavaFXWebViewElement.class);
add(GenericStyledArea.GENERIC_STYLED_AREA_CLASS, RichTextFXGenericStyledAreaElement.class);
}
public ExportTemplate(final @NotNull Pane templatesPane, final @NotNull SVGDocumentGenerator svgGen, final @NotNull JfxUI ui,
final @NotNull ProgressBar progressBar, final @NotNull Label statusWidget, final @NotNull Alert alertName,
final @NotNull TextInputDialog nameInput) {
super(null, svgGen, progressBar, statusWidget, ui);
this.templatesPane = templatesPane;
this.svgGen = svgGen;
this.nameInput = nameInput;
this.alertName = alertName;
}
@Test
public void select() {
ProgressBar progressBarNode = (ProgressBar) getPrimaryStage().getScene().getRoot().lookup(".progress-bar");
Platform.runLater(() -> {
progressBar.marathon_select("0.20");
});
new Wait("Wating for progress bar progress to be set.") {
@Override
public boolean until() {
return progressBarNode.getProgress() == 0.2;
}
};
}
public ProgressBarSample() {
super(400,100);
double y = 15;
final double SPACING = 15;
ProgressBar p1 = new ProgressBar();
p1.setLayoutY(y);
y += SPACING;
ProgressBar p2 = new ProgressBar();
p2.setPrefWidth(150);
p2.setLayoutY(y);
y += SPACING;
ProgressBar p3 = new ProgressBar();
p3.setPrefWidth(200);
p3.setLayoutY(y);
y = 15;
ProgressBar p4 = new ProgressBar();
p4.setLayoutX(215);
p4.setLayoutY(y);
p4.setProgress(0.25);
y += SPACING;
ProgressBar p5 = new ProgressBar();
p5.setPrefWidth(150);
p5.setLayoutX(215);
p5.setLayoutY(y);
p5.setProgress(0.50);
y += SPACING;
ProgressBar p6 = new ProgressBar();
p6.setPrefWidth(200);
p6.setLayoutX(215);
p6.setLayoutY(y);
p6.setProgress(1);
getChildren().addAll(p1,p2,p3,p4,p5,p6);
}
@Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.setTitle("Progress Controls");
for (int i = 0; i < values.length; i++) {
final Label label = labels[i] = new Label();
label.setText("progress:" + values[i]);
final ProgressBar pb = pbs[i] = new ProgressBar();
pb.setProgress(values[i]);
final ProgressIndicator pin = pins[i] = new ProgressIndicator();
pin.setProgress(values[i]);
final HBox hb = hbs[i] = new HBox();
hb.setSpacing(5);
hb.setAlignment(Pos.CENTER);
hb.getChildren().addAll(label, pb, pin);
}
final VBox vb = new VBox();
vb.setSpacing(5);
vb.getChildren().addAll(hbs);
scene.setRoot(vb);
stage.show();
}
@Override
protected void mouseReleased(MouseEvent me) {
ProgressBar progressBar = (ProgressBar) node;
String currentValue = getProgressText(progressBar);
if (currentValue != null && !currentValue.equals("-1")) {
recorder.recordSelect(this, currentValue);
}
}
@Test
public void select() {
ProgressBar progressBar = (ProgressBar) getPrimaryStage().getScene().getRoot().lookup(".progress-bar");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
RFXProgressBar rfxProgressBar = new RFXProgressBar(progressBar, null, null, lr);
progressBar.setProgress(0.56);
rfxProgressBar.mouseReleased(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("0.56", recording.getParameters()[0]);
}
public Parent createUpdater(FXManifest manifest) {
progressBar = new ProgressBar();
progressBar.setStyle(manifest.progressBarStyle);
Label label = new Label(manifest.updateText);
label.setStyle(manifest.updateLabelStyle);
VBox wrapper = new VBox(label, progressBar);
wrapper.setStyle(manifest.wrapperStyle);
return wrapper;
}
private GridPane createContent(double progress) {
this.progress = progress;
this.setMinWidth(420);
this.setMaxWidth(420);
this.getStyleClass().add("mw-ui-progressbar-container");
this.getColumnConstraints().addAll(
Util.newColumn(33, "%", HPos.LEFT),
Util.newColumn(33, "%", HPos.CENTER),
Util.newColumn(33, "%", HPos.RIGHT));
ProgressBar pb = new ProgressBar(progress);
pb.getStyleClass().addAll("mw-ui-progressbar");
pb.setMinWidth(420);
pb.setMaxWidth(420);
pb.setMaxHeight(5);
this.add(pb, 0, 0, 3, 1);
this.addRow(1,
createDot(0.0, 1),
createDot(1.0, 70),
createDot(2.0, 140));
this.addRow(2,
createLabel(0.0, labels[0]).setTranslateByHalf(false),
createLabel(1.0, labels[1]),
createLabel(2.0, labels[2]).setTranslateByHalf(true)
);
return this;
}
public void preInit() {
preInit = true;
rootElement = new VBox();
rootElement.setPadding(new Insets(10));
stage.getScene().setRoot(rootElement);
StackPane stackPane = new StackPane();
rootElement.getChildren().add(stackPane);
ProgressBar bar = new ProgressBar(-1);
stackPane.getChildren().add(bar);
stage.setWidth(ScreenDimension.D1024.width + CanvasControls.PREFERRED_WIDTH);
stage.setHeight(ScreenDimension.D1024.height + 100);
}