Results 1 to 2 of 2
  1. #1
    NerdNum is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default 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.


    Java 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
    
    }
    Thanks
    NerdNum

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

Similar Threads

  1. JDialog not showing content
    By etricky in forum AWT / Swing
    Replies: 12
    Last Post: 05-01-2011, 07:06 AM
  2. Replies: 4
    Last Post: 04-27-2011, 08:50 AM
  3. JFrame expanding to fit content
    By pcman312 in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 08:09 PM
  4. JPanel not showing up in JFrame
    By rlindsey in forum AWT / Swing
    Replies: 2
    Last Post: 06-25-2010, 08:21 AM
  5. Printing JFrame + it`s content
    By scana in forum AWT / Swing
    Replies: 1
    Last Post: 01-24-2010, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •