Results 1 to 2 of 2
Thread: JFrame Content not showing
- 05-05-2011, 09:43 AM #1
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
JFrame Content not showing
Hi
I have created a simple JFrame class (called ProgressWindow) that contains a label and a progress bar. Using a simple test program I am able to show the frame and update the progress bar from 0 to 100%. It worked fine.
I want to use the ProgressWindow in another application called SMSApplication. The SMSApplication calls a non-windowed class called ModemConnector. The ModemConnector is the class calling the ProgressWindow to show the progress of deleting messages stored on a GSM modem. However when the ModemConnector calls the ProgressWindow, the JFrame shows, but not the label or the progressbar. I have searched far and wide am not able to find a solution. Can someone please help.
I used Netbeans to create a JFrame form. Below is the code.
ThanksJava Code:package javasms; import java.awt.Dimension; import java.awt.Toolkit; public class ProgressWindow extends javax.swing.JFrame { private int maximum; private int value; private String label; public ProgressWindow(String title) { initComponents(); setTitle(title); Dimension dim = new Dimension(); dim.width = 360; dim.height = 100; setSize(dim); dim = Toolkit.getDefaultToolkit().getScreenSize(); int xSize = getHeight(); int ySize = getWidth(); int posX = (dim.height - xSize)/2; int posY = (dim.width - ySize)/2; setLocation(posY, posX); } public void setVisisble() { setVisible(true); //progressBar.revalidate(); //progressLabel.revalidate(); } public void close() { setVisible(false); dispose(); } public void updateProgressBar(int val) { setValue(val); progressBar.revalidate(); } public void updateProgressLabel(String lbl) { setLabel(lbl); progressLabel.revalidate(); } public void setLabel(String lbl) { label = lbl; progressLabel.setText(lbl); } public String getLabel() { return label; } public void setMaximum(int max) { maximum = max; progressBar.setMaximum(max); } public int getMaximum() { return maximum; } public void setValue(int val) { value = val; progressBar.setValue(val); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { progressLabel = new javax.swing.JLabel(); progressBar = new javax.swing.JProgressBar(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); progressLabel.setText("progress"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(progressLabel)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(progressLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(17, Short.MAX_VALUE)) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ProgressWindow("Test").setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JProgressBar progressBar; private javax.swing.JLabel progressLabel; // End of variables declaration }
NerdNum
- 05-05-2011, 09:53 AM #2
You're probably blocking the EDT.
Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
ProgressMonitor (Java Platform SE 6)
db
Similar Threads
-
JDialog not showing content
By etricky in forum AWT / SwingReplies: 12Last Post: 05-01-2011, 06:06 AM -
JMenuBar not showing on a JFrame unless resized manually.
By corrax in forum AWT / SwingReplies: 4Last Post: 04-27-2011, 07:50 AM -
JFrame expanding to fit content
By pcman312 in forum AWT / SwingReplies: 1Last Post: 12-31-2010, 07:09 PM -
JPanel not showing up in JFrame
By rlindsey in forum AWT / SwingReplies: 2Last Post: 06-25-2010, 07:21 AM -
Printing JFrame + it`s content
By scana in forum AWT / SwingReplies: 1Last Post: 01-24-2010, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks