-
Bug
-
Resolution: Fixed
-
P4
-
8
-
Java 1.8.0ea b97
Running under GTK in Linux
I am working with a custom Popup window in my application and I have noticed that the hover state of nodes inside the popup are reapplied to the nodes when the Popup is displayed again after being hidden.
It seems to be an issue with the Popup window because the hover remains even if I re-populate the Popup with fresh nodes each time it is displayed.
Run the provided test class and click on the label. Then click on either rectangle to dismiss the Popup. When you click a second time on the label the Popup will display with its previous hover state even though the test class has created new Rectangles for its content...
****************************************************************
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Popup;
import javafx.stage.Stage;
public class ListViewTest extends Application {
@Override public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(200);
primaryStage.setWidth(550);
final Label label = new Label("Click on me...");
final TestPopup popup = new TestPopup();
label.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
popup.show(primaryStage,
label.localToScreen(0, 0).getX(),
label.localToScreen(0, label.getHeight() + 10).getY() );
}
});
final Scene scene = new Scene(new StackPane(label));
primaryStage.setScene(scene);
// spawn a thread to write out a tempfile with our custom css and then
// show our stage.
new Thread(new Runnable() {
@Override
public void run() {
try {
final Path cssFile = Files.createTempFile("test", ".css");
cssFile.toFile().deleteOnExit();
Writer w = Files.newBufferedWriter(cssFile,
StandardCharsets.UTF_8);
w.write(".test { -fx-fill: dodgerblue; }\n"
+ ".test:hover {-fx-fill: magenta;}");
w.close();
Platform.runLater(new Runnable() {
@Override
public void run() {
scene.getStylesheets().add("file:" + cssFile.toString());
primaryStage.show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public static void main(String[] args) throws Exception {
launch(args);
}
private static class TestPopup extends Popup {
public TestPopup() {
setAutoHide(true);
}
@Override protected void show() {
Rectangle rect1 = new Rectangle(60, 60);
rect1.getStyleClass().add("test");
rect1.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
hide();
}
});
Rectangle rect2 = new Rectangle(60, 60);
rect2.getStyleClass().add("test");
rect2.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
hide();
}
});
getContent().setAll(new VBox(20, rect1, rect2));
super.show();
}
}
}
It seems to be an issue with the Popup window because the hover remains even if I re-populate the Popup with fresh nodes each time it is displayed.
Run the provided test class and click on the label. Then click on either rectangle to dismiss the Popup. When you click a second time on the label the Popup will display with its previous hover state even though the test class has created new Rectangles for its content...
****************************************************************
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Popup;
import javafx.stage.Stage;
public class ListViewTest extends Application {
@Override public void start(final Stage primaryStage) throws Exception {
primaryStage.centerOnScreen();
primaryStage.setHeight(200);
primaryStage.setWidth(550);
final Label label = new Label("Click on me...");
final TestPopup popup = new TestPopup();
label.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
popup.show(primaryStage,
label.localToScreen(0, 0).getX(),
label.localToScreen(0, label.getHeight() + 10).getY() );
}
});
final Scene scene = new Scene(new StackPane(label));
primaryStage.setScene(scene);
// spawn a thread to write out a tempfile with our custom css and then
// show our stage.
new Thread(new Runnable() {
@Override
public void run() {
try {
final Path cssFile = Files.createTempFile("test", ".css");
cssFile.toFile().deleteOnExit();
Writer w = Files.newBufferedWriter(cssFile,
StandardCharsets.UTF_8);
w.write(".test { -fx-fill: dodgerblue; }\n"
+ ".test:hover {-fx-fill: magenta;}");
w.close();
Platform.runLater(new Runnable() {
@Override
public void run() {
scene.getStylesheets().add("file:" + cssFile.toString());
primaryStage.show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public static void main(String[] args) throws Exception {
launch(args);
}
private static class TestPopup extends Popup {
public TestPopup() {
setAutoHide(true);
}
@Override protected void show() {
Rectangle rect1 = new Rectangle(60, 60);
rect1.getStyleClass().add("test");
rect1.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
hide();
}
});
Rectangle rect2 = new Rectangle(60, 60);
rect2.getStyleClass().add("test");
rect2.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
hide();
}
});
getContent().setAll(new VBox(20, rect1, rect2));
super.show();
}
}
}