Java Code Examples for javafx.scene.layout.BorderPane#setOnMouseClicked()

The following examples show how to use javafx.scene.layout.BorderPane#setOnMouseClicked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AboutDialog.java    From classpy with MIT License 5 votes vote down vote up
private static BorderPane createAboutPane(Stage dialogStage) {
    BorderPane pane = new BorderPane();
    //pane.setTop(new Label("Classpy"));
    pane.setCenter(ImageHelper.createImageView("/spy128.png"));
    pane.setBottom(createHomeLink());
    pane.setOnMouseClicked(e -> dialogStage.close());
    
    return pane;
}
 
Example 2
Source File: FXColorPicker.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constructs a new {@link FXColorPicker}.
 *
 * @param parent
 *            The parent {@link Composite}.
 * @param color
 *            The initial {@link Color} to set.
 */
public FXColorPicker(final Composite parent, Color color) {
	super(parent, SWT.NONE);
	setLayout(new FillLayout());

	FXCanvas canvas = new FXCanvas(this, SWT.NONE);

	// container
	Group colorPickerGroup = new Group();
	HBox hbox = new HBox();
	colorPickerGroup.getChildren().add(hbox);

	// color wheel
	WritableImage colorWheelImage = new WritableImage(64, 64);
	renderColorWheel(colorWheelImage, 0, 0, 64);
	ImageView colorWheel = new ImageView(colorWheelImage);
	colorWheel.setFitWidth(16);
	colorWheel.setFitHeight(16);

	BorderPane colorWheelPane = new BorderPane();
	Insets insets = new Insets(2.0);
	colorWheelPane.setPadding(insets);
	colorWheelPane.setCenter(colorWheel);
	// use background color of parent composite (the wheel image is
	// transparent outside the wheel, so otherwise the hbox color would look
	// through)
	colorWheelPane.setStyle("-fx-background-color: "
			+ computeRgbString(Color.rgb(parent.getBackground().getRed(),
					parent.getBackground().getGreen(),
					parent.getBackground().getBlue())));

	colorRectangle = new Rectangle(50, 20);
	// bind to ColorWheel instead of buttonPane to prevent layout
	// problems.
	colorRectangle.widthProperty().bind(colorWheel.fitWidthProperty()
			.add(insets.getLeft()).add(insets.getRight()).multiply(2.5));
	colorRectangle.heightProperty().bind(colorWheelPane.heightProperty());

	// draw 'border' around hbox (and fill background, which covers the
	// space beween color rect and wheel
	hbox.setStyle("-fx-border-color: " + computeRgbString(Color.DARKGREY)
			+ "; -fx-background-color: "
			+ computeRgbString(Color.DARKGREY));
	hbox.getChildren().addAll(colorRectangle, colorWheelPane);
	hbox.setSpacing(0.5);

	// interaction
	colorWheelPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			Color colorOrNull = FXColorPicker.pickColor(getShell(),
					getColor());
			if (colorOrNull != null) {
				setColor(colorOrNull);
			}
		}
	});

	Scene scene = new Scene(colorPickerGroup);

	// copy background color from parent composite
	org.eclipse.swt.graphics.Color backgroundColor = parent.getBackground();
	scene.setFill(Color.rgb(backgroundColor.getRed(),
			backgroundColor.getGreen(), backgroundColor.getBlue()));
	canvas.setScene(scene);

	// initialize some color
	setColor(color);

	colorRectangle.fillProperty().bind(this.color);
}