Example usage for javafx.scene.control Label setGraphic

List of usage examples for javafx.scene.control Label setGraphic

Introduction

In this page you can find the example usage for javafx.scene.control Label setGraphic.

Prototype

public final void setGraphic(Node value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Label Sample");
    stage.setWidth(400);/*from  w w w .jav  a2s  .  c  o m*/
    stage.setHeight(180);

    HBox hbox = new HBox();
    Image image = new Image(getClass().getResourceAsStream("labels.jpg"));
    Label label1 = new Label("Search");
    label1.setGraphic(new ImageView(image));

    hbox.setSpacing(10);
    hbox.getChildren().add((label1));
    ((Group) scene.getRoot()).getChildren().add(hbox);

    stage.setScene(scene);
    stage.show();
}

From source file:guipart.AddMessageUploadFile.java

private void setScene(Stage window) {
    fileNames = new ArrayList<File>();
    fileList = new ListView<String>();
    files = FXCollections.observableArrayList();
    fileList.setItems(files);//from  w w w .j a v a2 s.  c o m

    fileList.setTranslateY(-50);
    fileList.setMaxWidth(300);
    fileList.setMinHeight(150);

    Label addMessagesLabel = new Label("Add messages");
    Label loadedMessagesLabel = new Label("Loaded messages:");

    Label imageLabel2 = new Label();
    Image image2 = new Image(getClass().getResourceAsStream("/resources/gui/labelme_logo.png"));
    imageLabel2.setGraphic(new ImageView(image2));
    imageLabel2.setPrefSize(200, 200);
    HBox imageBox2 = new HBox();
    imageBox2.setAlignment(Pos.CENTER);
    imageBox2.setPadding(new Insets(20, 20, 20, 20));
    imageBox2.getChildren().add(imageLabel2);

    acceptButton = new Button("Accept All");
    browseButton = new Button("Browse");
    finishButton = new Button("Finish");
    previousButton = new Button("Previous");
    cancelButton = new Button("X");
    backButton = new Button("Back");
    pathField.setMinWidth(200);
    textCategory = new Label();

    addMessagesLabel.setFont(Font.font("Arial", FontWeight.BOLD, 28));

    HBox hBox = new HBox();
    hBox.setSpacing(20);
    hBox.getChildren().addAll(browseButton, pathField, acceptButton);
    hBox.setAlignment(Pos.CENTER);

    VBox layout = new VBox();
    layout.setSpacing(30);

    VBox filesPlaceholder = new VBox();
    filesPlaceholder.setSpacing(10);

    backButton.setTranslateY(-50);

    browseButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            //TODO: add more extensionFilters
            File currDir = new File(".");
            fileChooser.setInitialDirectory(currDir);
            fileChooser.getExtensionFilters().addAll((new FileChooser.ExtensionFilter("Text Files", "*.txt")));
            File file = fileChooser.showOpenDialog(window);

            if (file != null) {
                pathField.setText(file.getName());
                fileNames.add(file);
                files.add(file.getName());
            }
        }

    });

    fileList.setOnMouseClicked(e -> {
        //System.out.println(fileList.getSelectionModel().getSelectedItem());
        files.remove(fileList.getSelectionModel().getSelectedItem());
        for (File file : fileNames) {
            if (file.getName().equals(fileList.getSelectionModel().getSelectedItem())) {
                fileNames.remove(file);
                break;
            }
        }
    });

    acceptButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            if (!fileNames.isEmpty()) {
                Categorize categorize = new Categorize();
                categorize.trainModel();

                int size = files.size();

                for (int i = 0; i < size; i++) {
                    String fileName = files.get(i);
                    for (File file : fileNames) {
                        if (file.getName().equals(fileName)) {
                            try {
                                files.add(fileName + "      "
                                        + categorize.getCategory(FileUtils.readFileToString(file, "UTF-8")));
                            } catch (IOException ex) {
                                Logger.getLogger(AddMessageUploadFile.class.getName()).log(Level.SEVERE, null,
                                        ex);
                            }
                        }
                    }

                }

                int i = 0;
                while (i < size) {
                    files.remove(0);
                    i++;
                }
                /*
                try {
                textCategory.setText("The text category is: " + categorize.getCategory(FileUtils.readFileToString(fileNames.get(fileNames.size() - 1), "UTF-8")));
                } catch (IOException ex) {
                Logger.getLogger(AddMessageUploadFile.class.getName()).log(Level.SEVERE, null, ex);
                }*/
            }
            /*
            if (pathField.getText() != null) {
            int index = pathField.getText().lastIndexOf("\\");
                    
            Label messageLabel = new Label(pathField.getText().substring(index + 1));
            messageLabel.setMinWidth(200);
            messageLabel.setMinHeight(25);
            messageLabel.setStyle("-fx-fill: orange;\n"
                    + "-fx-border-color: blue;\n"
                    + "-fx-border-width: 3;\n");
            if (filesPlaceholder.getChildren().size() != 0) {
                layout.getChildren().remove(layout.getChildren().size() - 1);
            }
                    
            filesPlaceholder.getChildren().addAll(messageLabel);
            filesPlaceholder.setAlignment(Pos.CENTER);
            filesPlaceholder.setPadding(new Insets(0, 0, 0, 50));
                    
            layout.getChildren().add(filesPlaceholder);
            }*/
        }
    });

    backButton.setOnAction(e -> {
        window.setScene(mainPage.mainPageScene);

    });

    layout.getChildren().addAll(imageLabel2, addMessagesLabel, hBox, textCategory, fileList, backButton);
    layout.setStyle("-fx-background-color: white");
    layout.setAlignment(Pos.TOP_CENTER);
    layout.setStyle("-fx-background-color: #B8EDFF;");
    scene = new Scene(layout, 900, 600);
}

From source file:com.chart.SwingChart.java

/**
 * /*w w w.j  av a2  s.  co m*/
 * @param axis Axis name to wich the new series belongs
 * @param cs Series Coinfiguration
 */
@Override
public final void addSeries(String axis, SimpleSeriesConfiguration cs) {
    for (int i = 0; i < axes.size(); i++) {
        if (axes.get(i).getName().equals(axis)) {
            String strColor;
            javafx.scene.paint.Color color;
            int indice = seriesList.size();
            if (cs.getColor() == null) {
                color = getColor(indice);
            } else {
                color = cs.getColor();
            }
            strColor = color.toString();

            XYSeriesCollection dataset = datasetList.get(i);
            Series series = new Series(cs.getName(), "color: " + strColor + ";width: "
                    + String.valueOf(cs.getLineWidth()) + ";shape: " + cs.getShapeName() + ";", i,
                    dataset.getSeriesCount());
            dataset.addSeries(series);

            XYItemRenderer renderer = plot.getRenderer(i);
            renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color));

            SeriesShape simb = new SeriesShape(cs.getShapeName(),
                    javafx.scene.paint.Color.web(strColor.replace("#", "0x")));

            if (cs.getLineWidth() > 0) {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, true);
                renderer.setSeriesStroke(dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth()));
            } else {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, false);
            }

            if (cs.getShapeName().equals("null")) {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, null);
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, false);
            } else {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT());
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, true);
                if (cs.getShapeName().contains("empty")) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            false);
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            true);
                }
            }

            if (i == 0) {
                plot.setRenderer(renderer);
            } else {
                plot.setRenderer(i, renderer);
            }

            seriesList.add(series);

            final LegendAxis le = getLegendAxis(axis);
            final Label label = new Label(cs.toString());
            Platform.runLater(() -> {
                label.setStyle("fondo: " + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize) + "px");
            });

            label.setOnMouseClicked((MouseEvent t) -> {
                if (t.getClickCount() == 2) {
                    for (int i1 = 0; i1 < seriesList.size(); i1++) {
                        if (seriesList.get(i1).getKey().toString().equals(label.getText())) {
                            editSeries(seriesList.get(i1));
                            break;
                        }
                    }
                }
            });
            label.setOnMouseExited((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: blue", "-fx-background-color: fondo"));
            });
            label.setOnMouseEntered((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: fondo", "-fx-background-color: blue"));
                for (Node le1 : legendFrame.getChildren()) {
                    if (le1 instanceof LegendAxis) {
                        le1.setStyle("-fx-background-color:" + strBackgroundColor);
                        ((LegendAxis) le1).selected = false;
                    }
                }
            });
            label.setStyle("fondo: " + strChartBackgroundColor
                    + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                    + String.valueOf(fontSize) + "px");

            le.getChildren().add(label);
            label.setGraphic(simb.getShapeGraphic());

            break;
        }
    }
}

From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java

private void autoComplete(int slashPosition, String input, ContextMenu autoCompletePopup) {

    XPathSuggestions xPathSuggestions = new XPathSuggestions(parent.getLanguageVersion().getLanguage());
    List<String> suggestions = xPathSuggestions.getXPathSuggestions(input.trim());

    List<CustomMenuItem> resultToDisplay = new ArrayList<>();
    if (!suggestions.isEmpty()) {

        for (int i = 0; i < suggestions.size() && i < 5; i++) {
            final String searchResult = suggestions.get(i);

            Label entryLabel = new Label();
            entryLabel.setGraphic(highlightXPathSuggestion(suggestions.get(i), input));
            entryLabel.setPrefHeight(5);
            CustomMenuItem item = new CustomMenuItem(entryLabel, true);
            resultToDisplay.add(item);/* w  w  w.  java 2  s  . co  m*/

            item.setOnAction(e -> {
                xpathExpressionArea.replaceText(slashPosition, slashPosition + input.length(), searchResult);
                autoCompletePopup.hide();
            });
        }
    }
    autoCompletePopup.getItems().setAll(resultToDisplay);

    xpathExpressionArea.getCharacterBoundsOnScreen(slashPosition, slashPosition + input.length()).ifPresent(
            bounds -> autoCompletePopup.show(xpathExpressionArea, bounds.getMinX(), bounds.getMaxY()));
}