Link to home
Start Free TrialLog in
Avatar of spetrowitsch
spetrowitsch

asked on

JFrame as MessageBox doesn´t show it´s controls

Hi,
 
I want to show the progress of loading records from a database into my JTree and a label in a JFrame. But - the label and the progressbar doesn´t appear in my JFrame-window.

I added the following class:


package DokViewer;

import java.awt.*;
import java.awt.Color;
import javax.swing.*;
import com.borland.jbcl.layout.*;

public class Fortschrittsanzeige extends JFrame
{
  JLabel jLabel1;
  JProgressBar jProgressBar1;
  VerticalFlowLayout verticalFlowLayout1;

  public Fortschrittsanzeige()
  {
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  public void Close()
  {
    this.setVisible(false);
    // finalize(); // not necessary?
  }

  private void jbInit() throws Exception
  {
    jLabel1 = new JLabel();
    jProgressBar1 = new JProgressBar();
    verticalFlowLayout1 = new VerticalFlowLayout();

     
    this.getContentPane().setLayout(verticalFlowLayout1);
    this.setResizable(false);
    jProgressBar1.setMaximumSize(new Dimension(150, 16));
    jProgressBar1.setMinimumSize(new Dimension(150, 16));
    jProgressBar1.setMaximum(100);
    jProgressBar1.setMinimum(0);
    jLabel1.setMaximumSize(new Dimension(374, 32));
    jLabel1.setMinimumSize(new Dimension(187, 16));
    jLabel1.setPreferredSize(new Dimension(187, 16));
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setText("Patientendaten werden geladen ...");
    jLabel1.setVerticalAlignment(SwingConstants.TOP);
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jProgressBar1, null);
    jLabel1.setVisible(true);
    // Kein Menü in diesem Frame
    this.setMenuBar(null);
    // Größe setzen, sonst gibt´s nur den Überschriftsbalken als Anzeige
    this.setSize(250, 70);
  }

  public void SetValue(int nProzent)
  { jProgressBar1.setValue(nProzent);
  }
}

I call this from my super-class like this:



Fortschrittsanzeige jFortschrittFrame = new Fortschrittsanzeige();
       
Dimension dlgSize = jFortschrittFrame.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
jFortschrittFrame.setLocation((frmSize.width - dlgSize.width) / 2 +
 loc.x,
 (frmSize.height - dlgSize.height) / 2 +
 loc.y);
jFortschrittFrame.setVisible(true);
jFortschrittFrame.show();

... but: the text and the ProgressBar doesn´t appear in my window. There is only a white background (and this is set to LightGray with the properties in my JBuilder-design-window.)

Thank´s in advance for your help.
ASKER CERTIFIED SOLUTION
Avatar of momlal
momlal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of spetrowitsch
spetrowitsch

ASKER

Hi momlal,

I call several times the method
jFortschrittFrame.SetValue(...);

Shouldn´t that be o.k.?
HI spetrowitsch,
The problem is not howmany times you call "setValue" but that the frame doesn't receive paint events.
One solution is loading from the database in Thread the other is calling repaint() method of the frame from time to time.
HI spetrowitsch,
The problem is not howmany times you call "setValue" but that the frame doesn't receive paint events.
One solution is loading from the database in Thread the other is calling repaint() method of the frame from time to time.