I have a strange problem ... I am a relatively new "enthusiast" Java programmer (I used to hack Perl in my previous career) while working on my first semi-real application. The "main class" is the MyApp class, which creates an instance of UserInputDialog .
UserInputDialog is a class that I wrote that extend JFrame implements ActionListener and KeyListener , uses FlowLayout and presents the user with JLabel , JTextField and Cancel / OK JButton s. When a JTextField generates a KeyEvent , where keyReleased() == KeyEvent.VK_ENTER , or when the JButton "OK" generates an ActionEvent , UserInputDialog does some input checking, calls setVisible(false) , and then calls MyApp.doSomething( JTextFieldInstance.getText() ) .
Everything works perfectly. But now I'm trying to add a progress window to MyApp , since doSomething() can take a sufficient amount of time from time to time.
I created a ProgressWindow class that extends a JFrame , uses a BorderLayout and sends a JProgressBar in. NORTH and a JScrollPane (wrapping a JTextArea ) in. CENTER , ProgressWindow works great when creating an instance of ProgressWindowTester and passes test data. It also works great if I copy and paste the test for loops from ProgressWindowTester to MyApp and does not have MyApp instantiate UserInputDialog ( UserInputDialog is inherent to MyApp causing this behavior; this seems to be some kind of interaction that I don't understand , between UserInputDialog and ProgressWindow ).
But when I try to use ProgressWindow in MyApp as intended, i.e. ProgressWindow setVisible (true), I get an empty Swing window (of the appropriate size and the correct title bar). JProgressBar and JScrollPane / JTextArea not displayed. The ProgressWindow methods are called correctly by MyApp ( System.err.println() messages show the correct interaction), everything works fine, just the components that should be visible in ProgressWindow ... are not.
I can post code snippets, but this is a bit confusing, and I will probably just miss something obvious ...
I am familiar with the concept of separating the user interface and the business logic as a whole (for example, I used HTML::Template and Class::DBI and CGI::Application when creating Perl applications), but I'm not sure that I am βdoing it rightβ in Java ...
Thanks in advance!
Oh, I get exactly the same behavior in two environments in which I tried the code: javac 1.6.0_29 on Mac OS X 10.6.8 ("Snow Leopard"); and javac 1.7.0_02 [1] on the Linux Fedora 15 distribution, kernel 2.6.31.10-3, the LXDE desktop environment.
[1] Downloaded directly from oracle.com; I do not use OpenJDK (I know that JDK 7 is based on OpenJDK) or gcj or something like that