如何更改拾色器(JavaFX)的位置

时间:2015-12-30 16:14:52

标签: java canvas javafx

我有一个拾色器,但它总是位于屏幕中间,我的问题是,如何为拾色器设置X和Y坐标?

我已经尝试了relocatesetlayoutX,但是这样做了:(

package gui;

import display.Image;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Stage;



public class JavaFXColorPicker extends Application {
private Image head;
private Image heart;

@Override
public void start(Stage primaryStage) throws IOException {
    StackPane root = new StackPane();
    Scene scene = new Scene(root, 300, 300, Color.BLACK);   
    final Canvas canvas = new Canvas(250,250);
    GraphicsContext gc = canvas.getGraphicsContext2D();





    ColorPicker HeadColor = new ColorPicker();
    ColorPicker BodyColor = new ColorPicker();
    ColorPicker LegColor = new ColorPicker();



    HeadColor.setOnAction(new EventHandler(){

        @Override
        public void handle(Event event) {
            Color HeadPaint = HeadColor.getValue();
            Color[] HeadColorArray = new Color[]
        {
            new Color(0 , 0, 0, 1),
            HeadPaint,
            HeadPaint,
            HeadPaint,
            HeadPaint,
            new Color(1, 1, 1, 1) // de ogen
        };
            try {
                head = new display.Image(display.Parts.playerHead);
            } catch (IOException ex) {
                Logger.getLogger(JavaFXColorPicker.class.getName()).log(Level.SEVERE, null, ex);
            }


            head.recolour(HeadColorArray);
            Image i = head;
            gc.drawImage(i.show(), 30, 100);


        }

    });




    head = new display.Image(display.Parts.playerHead);
    Image i = head;
    gc.drawImage(i.show(), 10, 100);



    root.getChildren().add(canvas);






    root.getChildren().add(HeadColor);
    primaryStage.setTitle("Customize Character!");
    primaryStage.setScene(scene);
    primaryStage.show();




}

public static void main(String[] args) {
    launch(args);


}

}

0 个答案:

没有答案