2011-12-29 11 views
7

Sto cercando di creare uno stage personalizzato in javafx 2.0. Voglio che la mia fase scende ombra sullo schermo come sceso di altre finestre ... ho provato con seguente codice:creazione di stage non decorati in javafx 2.0

public class ChatWindow { 
final private Stage stage = new Stage(StageStyle.UNDECORATED); 
private Scene scene; 
private Group rg; 
private Text t = new Text(); 
private double initx = 0, inity = 0; 

public ChatWindow() { 

    rg = new Group(); 
    scene = new Scene(rg, 320, 240); 
    //scene.setFill(null); 
    scene.setFill(new Color(0, 0, 0, 0)); 
    stage.setScene(scene); 
    stage.show(); 
    setupStage(); 
} 

private void setupStage() { 
    Rectangle r = new Rectangle(5, 5, stage.getWidth() - 10, stage.getHeight() - 10); 
    r.setFill(Color.STEELBLUE); 
    r.setEffect(new DropShadow()); 
    rg.setOnMousePressed(new EventHandler<MouseEvent>() { 
     public void handle(MouseEvent me) { 
      initx = me.getScreenX() - stage.getX();// - me.getSceneX(); 
      inity = me.getScreenY() - stage.getY(); 
     } 
    }); 
    rg.setOnMouseDragged(new EventHandler<MouseEvent>() { 

     public void handle(MouseEvent me) { 
      stage.setX(me.getScreenX() - initx); 
      stage.setY(me.getScreenY() - inity); 
     } 
    }); 
    rg.getChildren().add(r); 
    rg.getChildren().add(t); 
} 

public void setVisible() { 
    stage.show(); 
} 
} 

posso vedere la caduta ombra, ma in realtà il loro è uno sfondo bianco in cui la sua caduta. Così, la sua inutile, come sullo schermo colorato il difetto sarà visibile, sarà far sembrare brutta ..

Questo è il colpo dello schermo sullo schermo bianco: enter image description here

E questo sullo schermo colorato: enter image description here

Ho risolto questo problema ?? Per favore aiuto.

risposta

10

È necessario impostare lo stile StageStyle.TRANSPARENT, vedere codice successivo:

public class ChatWindow extends Application { 

    @Override 
    public void start(final Stage stage) throws Exception { 
     stage.initStyle(StageStyle.TRANSPARENT); // here it is 

     Group rg = new Group(); 
     Scene scene = new Scene(rg, 320, 240, Color.TRANSPARENT); 
     stage.setScene(scene); 
     stage.show(); 

     Rectangle r = new Rectangle(5, 5, stage.getWidth() - 10, stage.getHeight() - 10); 
     r.setFill(Color.STEELBLUE); 
     r.setEffect(new DropShadow()); 
     rg.getChildren().add(r); 
    } 

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