Swing/JavaFx Hybrid Application with crashing TextField - swing

I have a problem which is affecting an application that for various reasons had to be written using Swing JFrames containing JavaFx panels. I can reduce the code to a simple example, based on code from https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm.
My example opens an application containing a button that can open a simple dialog which has a textfield. If I type into the dialog's textfield, everything is fine, but if I start typing then click on anything outside the dialog (e.g. a text editor), when i go back to the textfield and type some more if behaves oddly and starts throwing exceptions. This appears to be where something is not happening on the EDT or Application thread, and I'm quite sure it's down the the dialog's show() method, though I can't see what is wrong. As far as i can tell, i've followed the correct pattern.
I'm using JDK 1.8.0_171 and IntelliJ Idea on Windows 10.
The code is as follows:
Application:
public class HybridApplication
{
private static JFrame frame;
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> initAndShowGUI());
}
private static void initAndShowGUI() {
frame = new JFrame("Swing and JavaFX");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(() -> initFX(fxPanel));
}
private static void initFX(JFXPanel fxPanel) {
Scene scene = createScene();
fxPanel.setScene(scene);
}
private static Scene createScene() {
HBox hBox = new HBox();
hBox.setSpacing(20);
Scene scene = new Scene(hBox);
TextField text = new TextField();
text.setPrefWidth(200);
text.setPrefHeight(40);
HybridDialog dialog = new HybridDialog();
Button button = new Button("Test");
button.setOnAction(event -> dialog.show());
hBox.getChildren().add(button);
hBox.getChildren().add(text);
return scene;
}
}
Dialog:
public class HybridDialog
{
private JFrame frame;
public HybridDialog()
{
SwingUtilities.invokeLater(() -> initAndShowGUI());
}
private void initAndShowGUI()
{
frame = new JFrame("Dialog");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setSize(300, 200);
frame.setVisible(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Platform.runLater(() -> initFX(fxPanel));
}
private void initFX(JFXPanel fxPanel) {
Scene scene = createScene();
fxPanel.setScene(scene);
}
private static Scene createScene() {
TextField text = new TextField();
text.setPrefWidth(200);
text.setPrefHeight(40);
HBox hBox = new HBox();
hBox.getChildren().add(text);
Scene scene = new Scene(hBox);
return scene;
}
public void show() {
SwingUtilities.invokeLater(() -> frame.setVisible(true));
}
}
The odd behaviour is that when i resume typing, say to edit what i'd typed, the textfield starts adding chunks of the text after the cursor and I soon get the following exception:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1273)
at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223)
at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246)
at javafx.scene.text.Text.getLogicalBounds(Text.java:358)
at javafx.scene.text.Text.getYRendering(Text.java:1069)
at javafx.scene.text.Text.access$4400(Text.java:95)
at javafx.scene.text.Text$TextAttribute$11.computeValue(Text.java:1785)
at javafx.scene.text.Text$TextAttribute$11.computeValue(Text.java:1777)
at javafx.beans.binding.ObjectBinding.get(ObjectBinding.java:153)
at javafx.beans.binding.ObjectExpression.getValue(ObjectExpression.java:50)
at javafx.beans.property.ObjectPropertyBase.get(ObjectPropertyBase.java:132)
at com.sun.javafx.scene.control.skin.TextFieldSkin.lambda$new$198(TextFieldSkin.java:233)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.access$000(ObjectPropertyBase.java:51)
at javafx.beans.property.ObjectPropertyBase$Listener.invalidated(ObjectPropertyBase.java:233)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.binding.ObjectBinding.invalidate(ObjectBinding.java:172)
at javafx.scene.text.Text.impl_geomChanged(Text.java:769)
at javafx.scene.text.Text.needsTextLayout(Text.java:194)
at javafx.scene.text.Text.needsFullTextLayout(Text.java:189)
at javafx.scene.text.Text.access$200(Text.java:95)
at javafx.scene.text.Text$2.invalidated(Text.java:389)
at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:109)
at javafx.beans.property.StringPropertyBase.access$000(StringPropertyBase.java:49)
at javafx.beans.property.StringPropertyBase$Listener.invalidated(StringPropertyBase.java:230)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.binding.StringBinding.invalidate(StringBinding.java:171)
at com.sun.javafx.binding.BindingHelperObserver.invalidated(BindingHelperObserver.java:51)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.scene.control.TextInputControl$TextProperty.fireValueChangedEvent(TextInputControl.java:1389)
at javafx.scene.control.TextInputControl$TextProperty.markInvalid(TextInputControl.java:1393)
at javafx.scene.control.TextInputControl$TextProperty.controlContentHasChanged(TextInputControl.java:1332)
at javafx.scene.control.TextInputControl$TextProperty.access$1600(TextInputControl.java:1300)
at javafx.scene.control.TextInputControl.lambda$new$162(TextInputControl.java:139)
at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.scene.control.TextField$TextFieldContent.insert(TextField.java:87)
at javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:1204)
at javafx.scene.control.TextInputControl.updateContent(TextInputControl.java:556)
at javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:548)
at com.sun.javafx.scene.control.skin.TextFieldSkin.replaceText(TextFieldSkin.java:576)
at com.sun.javafx.scene.control.behavior.TextFieldBehavior.replaceText(TextFieldBehavior.java:202)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.defaultKeyTyped(TextInputControlBehavior.java:238)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:139)
at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:127)
at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$null$299(EmbeddedScene.java:310)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$keyEvent$300(EmbeddedScene.java:296)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
If i keep typing, the following line appears in the IDE as if locked in a loop:
Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException
Thanks, in advance, for any help anyone can give.

Related

How do I fix aligning issues when using JFXPanel?

My problem is, that i have a normal JavaFX fxml file, which automatically realigns its elements when i start it normally and resize it. But i when i start it with the JFXPanel suddenly nothing realigns anymore. And i have no idea what the reason could be. (I have to use this method to start my gui, there is no other way)
My code:
final JFXPanel panel = new JFXPanel();
panel.addComponentListener(new ComponentAdapter() {
#Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
// Maybe here some code?
}
});
JFrame frame = new JFrame();
Platform.runLater(() -> {
try {
Group root = new Group();
Scene scene = new Scene(root);
FXMLLoader loader = new FXMLLoader(getClass().getResource("myGui.fxml"));
Node node = loader.load();
root.getChildren().add(node);
panel.setScene(scene);
} catch (IOException e) {
e.printStackTrace();
}
});
frame.add(panel);
frame.pack();
frame.setVisible(true);
I researched for hours and don't really find a solution to my problem. Maybe i searched wrong? i would be really grateful if someone could help me.
Im a bit suspicious with the Group object "root" but i have no clue what it does. (I have this code from a website, because im inexperienced with JFXPanels so im not entirely sure what every line does)
My whole class:
public class Test {
public static void main(String[] args) {
Test test = new Test();
test.startGui();
}
public void startGui() {
final JFXPanel panel = new JFXPanel();
panel.setPreferredSize(new Dimension(600, 400));
panel.addComponentListener(new ComponentAdapter() {
#Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
// Maybe here some code?
}
});
JFrame frame = new JFrame();
Platform.runLater(() -> {
try {
Group root = new Group();
Scene scene = new Scene(root);
FXMLLoader loader = new FXMLLoader(getClass().getResource("myGui.fxml"));
Node node = loader.load();
root.getChildren().add(node);
panel.setScene(scene);
} catch (IOException e) {
e.printStackTrace();
}
});
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
And my fxml file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<StackPane prefHeight="150.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
<children>
<Label text="left" />
</children>
</StackPane>
<StackPane prefHeight="150.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
<children>
<Label text="right" />
</children>
</StackPane>
</children>
</HBox>
When you start the gui and resize it the left and right label should go further away. They should have the same distance to the borders of the gui.
You are adding the JFXPanel to a JFrame which uses BorderLayout by default.
To change the resizing and positioning of the JFXPanel set other layout manager.
For example:
frame.setLayout(new GridBagLayout());

swing application opens and closes down immediately when invoked with assertJ command (TestNG + assertJ Swing)

Trying assertJ-swing for UI testing of java-swing based application.
Situation: Sample application in JavaApp.java (with Main class) works fine when it is invoked from this java file (running it as Java application). But when it is invoked from TestNG with assertj-swing's command:
application(JavaApp.class).start();
the application opens up but closes down immediately.
Question: Is it the only approach? Please suggest resolution or any other approach to launch the application and keep it open so further operations can be performed.
JavaApp:
package jdialogdemo;
import java.awt.*;
import java.awt.event.*;
import javax.lang.model.util.SimpleElementVisitor6;
import javax.swing.*;
public class JavaApp {
public static void main(String[] args) throws Exception {
final JFrame frame = new JFrame("JDialog Demo");
final JButton btnLogin = new JButton("Click to login");
btnLogin.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) {
LoginDialog loginDlg = new LoginDialog(frame);
loginDlg.setVisible(true);
// if logon successfully
if(loginDlg.isSucceeded()){
btnLogin.setText("Hi " + loginDlg.getUsername() + "!");
}
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700, 200);
frame.setLocationRelativeTo(null);
frame.setLayout(new FlowLayout());
frame.getContentPane().add(btnLogin);
frame.setVisible(true);
}
}
AssertJ-Swing verifies that you only do access swing components on the EDT (as required because Swing is not thread safe, see Concurrency in Swing - Initial threads).
Your main method violates this (by constructing the UI from the main thread) and therefore AssertJ-Swing fails with an exception.
To correct the problem your main method should look like this:
public class JavaApp {
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(() -> {
final JFrame frame = new JFrame("JDialog Demo");
final JButton btnLogin = new JButton("Click to login");
//...
});
}
}

JavaFX ChoiceBox ContextMenu shown again when it is displayed and clicked again

I have JavaFX panel with ChoiceBox in Swing application. Standard behaviour of ChoiceBox is that when you click it for the first time the popup menu with items is shown and when you click ChoiceBox for the second time, the popup menu is hidden. But when you put it to Swing application the second click causes popup to hide and to be shown immediately again. How can I prevent this behaviour?
public class ComboTest {
private static void initAndShowGUI() {
JFrame frame = new JFrame("FX");
final JFXPanel fxPanel = new JFXPanel();
fxPanel.setPreferredSize(new Dimension(100, 100));
frame.add(fxPanel);
frame.pack();
frame.setVisible(true);
Platform.runLater(new Runnable() {
#Override
public void run() {
initFX(fxPanel);
}
});
}
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
initAndShowGUI();
}
});
}
private static Scene createScene() {
ChoiceBox choiceBox = new ChoiceBox(FXCollections.observableArrayList("item 1", "item 2"));
VBox vbox = new VBox(choiceBox);
return new Scene(vbox);
}
}
My suspicion is that when I click the choicebox for the second time the popup loses focus which causes it to hide and the choicebox then handles mouse click and shows the popup again.
I believe that this problem caused by the existing ChoiceBox bug in javafx.
The simplest fix is just to use ComboBox instead:
ComboBox<String> choiceBox = new ComboBox<>(FXCollections.observableArrayList("item 1", "item 2"));

Java swing JPanel example, GLCanvas error

public class Activator implements BundleActivator {
TestFrame testFrame = new TestFrame();
public static JPanel graphPanel;
public void start(BundleContext context) throws Exception {
graphPanel = cartesianGraphs.getGraphPanel();
testFrame.getPanel1().add(graphPanel);
testFrame.setVisible(true);
}
}
public class TestFrame extends JFrame {
private static final long serialVersionUID = 1L;
private library kutuphane = null;
private JPanel contentPane;
private JTabbedPane tabbedPane;
private JPanel panel1;
private JButton btn;
public TestFrame() {
initComponents();
}
private void initComponents() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 800, 600);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
contentPane.add(getTabbedPane(), BorderLayout.CENTER);
contentPane.add(getBtn(), BorderLayout.NORTH);
}
public JPanel getPanel1() {
if (panel1 == null) {
panel1 = new JPanel();
panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
}
return panel1;
}
private JButton getBtn() {
if (btn == null) {
btn = new JButton("Remove All and Add");
btnTabSil.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
TestFrame.this.getPanel1().removeAll();
Activator.graphPanel.revalidate();
// where it throws the exception is below
TestFrame.this.getPanel1().add(Activator.graphPanel);
TestFrame.this.revalidate();
TestFrame.this.repaint();
TestFrame.this.setVisible(true);
}
});
}
return btn;
}
}
In the activator class above I add (JPanel )graphpanel into (JPannel) testFrame.getPanel1() Then with a button in the testFrame class I used removeAll() method and add the static graphPannel again but I got the error below.
When I debug it I see that GLcanvas looses the peer. I couldnt find a solution.
Exception in thread "Thread-3" java.lang.RuntimeException:
javax.media.opengl.GLException: Unable to create temp OpenGL context
for device context 0xffffffffde01148b at
jogamp.common.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58) at
jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
at
jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
at
javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191) at
javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:449) at
grafik.view.grafik.Gcontroller.draw(Gcontroller.java:169) at
grafik.model.data.Dcontroller.drawAll(Dcontroller.java:272) at
grafik.view.Wcontroller.GdataClean(Wcontroller.java:261) at
grafik.view.WThread.run(WThread.java:57) Caused by:
javax.media.opengl.GLException: Unable to create temp OpenGL context
for device context 0xffffffffde01148b at
jogamp.opengl.windows.wgl.WindowsWGLContext.createImpl(WindowsWGLContext.java:306)
at
jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:572)
at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:485)
at
jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:645)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:594)
at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:996) at
java.awt.event.InvocationEvent.dispatch(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$300(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.awt.EventQueue$3.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source)
Please switch to JOGL 2.3.1. Then, replace "javax.media" by "com.jogamp" to avoid any compile error.
When you remove the AWT GLCanvas from its parent container, it loses its peer and its OpenGL context is destroyed. This is something that you can't avoid when using this kind of canvas. Switch to NEWT if this isn't the desired behavior.
The creation of another context might fail in some particular cases on some hardware. If you still get the same stack trace with the latest version of JOGL, please fill a bug report: http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing

FEST JUnit-Swing testing noobQ: how to test a main class?

Despite reading the tutorial here, I cant seem to understand how to make FEST work with my application.
I have a Swing application in a big class witht a main method, and a couple of SwingWorker classes. I want to test my application as if I'm running it via the main method. The tutorial only seemed to give instructions on how to test a single component.
Miniature version of my ApplicationWindow.class that contains the main method:
private JFrame frmArtisol;
private JButton btnBrowseDB;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ApplicationWindow window = new ApplicationWindow();
window.frmArtisol.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public ApplicationWindow() {
initialize();
}
And my testclass throwing an error.
public class ApplicationWindowTest {
private FrameFixture window;
#Before
public void setup() throws InitializationError{
ApplicationWindow applicationWindow = new ApplicationWindow();
JFrame frame = applicationWindow.getFrmArtisol();
frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
#Override
protected JFrame executeInEDT() throws Throwable {
return new JFrame();
}
});
window = new FrameFixture(frame);
window.show();
}
#Test
public void test(){
window.button("btnBrowseDB").click();
}
#After
public void after(){
window.cleanUp();
}
}
The error thrown when running this test:
org.fest.swing.exception.ComponentLookupException: Unable to find component using matcher org.fest.swing.core.NameMatcher[name='btnBrowseDB', type=javax.swing.JButton, requireShowing=true].
Component hierarchy:
javax.swing.JFrame[name='frame0', title='', enabled=true, visible=true, showing=true]
javax.swing.JRootPane[]
javax.swing.JPanel[name='null.glassPane']
javax.swing.JLayeredPane[]
javax.swing.JPanel[name='null.contentPane']
at org.fest.swing.core.BasicComponentFinder.componentNotFound(BasicComponentFinder.java:271)
at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:260)
at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:254)
at org.fest.swing.core.BasicComponentFinder.findByName(BasicComponentFinder.java:191)
at org.fest.swing.fixture.ContainerFixture.findByName(ContainerFixture.java:527)
at org.fest.swing.fixture.ContainerFixture.button(ContainerFixture.java:124)
at ApplicationWindowTest.test(ApplicationWindowTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
It seems as if the runner doesn't find my component, and this leads me to believe that I have misunderstood how to test this kind of thing. Any help pointing me in the right direction is greatly appreciated.
You may have already solved this, but I just came across your question while looking for help with a related problem.
The problem is that your setup() method creates an ApplicationWindow but then overwrites the variable frame with a reference to a completely new and unrelated JFrame object. What you want to do is create the ApplicationWindow in the executeInEDT() method like this:
#Before
public void setup() throws InitializationError{
JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
#Override
protected JFrame executeInEDT() throws Throwable {
return new ApplicationWindow().getFrmArtisol();
}
});
window = new FrameFixture(frame);
window.show();
}