JDialog does not display properly

H

hello_world

Hi,

I've developed an applet which enables multiple file uploads via http
using HttpClient 3.0. During the upload process, I would like to
display a non-modal dialog box with some text and an animation
(basically a message - "uploading" - and an animated GIF). As soon as
upload is over, the dialog box should disappear.

To achieve this, I use a JDialog, and within it, a JPanel containing 2
JLabels: one for the text message and the other for the GIF image. My
problem is I get a grey area, the size of my dialog, with no controls
whatsoever inside, when I try to display the dialog!

I would be grateful if someone could help me resolve this issue. Please
see code below:

-------- my dialog class --------

public class TransferProgressDialog extends javax.swing.JDialog{

private javax.swing.JLabel caption;
private javax.swing.JLabel progressImg;
private javax.swing.JPanel progressAnimJPanel;
private java.awt.Component component;

private int posX, posY;

public TransferProgressDialog(java.awt.Component component, String
folderName){
initComponents();
this.component = component;
this.setLocationRelativeTo(component);
caption.setText("Uploading " + folderName);
}

public void showDialog(){
this.setVisible(true);
component.setEnabled(false);
}

public void hideDialog(){
this.hide();
component.setEnabled(true);
}

private void dialogMousePressed(java.awt.event.MouseEvent evt) {
posX = evt.getX();
posY = evt.getY();
}

private void dialogMouseDragged(java.awt.event.MouseEvent evt) {
int deltaX = evt.getX() - posX;
int deltaY = evt.getY() - posY;

java.awt.Point pt = this.getLocation();
this.setLocation(pt.x + deltaX, pt.y + deltaY);
}

private void initComponents(){
java.awt.GridBagConstraints gridBagConstraints;

progressAnimJPanel = new javax.swing.JPanel();
caption = new javax.swing.JLabel();
progressImg = new javax.swing.JLabel();

progressAnimJPanel.setLayout(new java.awt.GridBagLayout());

progressAnimJPanel.setBorder(new
javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));

caption.setFont(new java.awt.Font("Tahoma", 1, 10));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(caption, gridBagConstraints);

progressImg.setIcon(new
javax.swing.ImageIcon("./loading.gif"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipady = 7;
progressAnimJPanel.add(progressImg, gridBagConstraints);

this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
dialogMousePressed(evt);
}
});

addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
{
public void mouseDragged(java.awt.event.MouseEvent evt) {
dialogMouseDragged(evt);
}
});

this.setContentPane(progressAnimJPanel);
this.setSize(140, 80);
this.setUndecorated(true);
this.setAlwaysOnTop(true);
}

}

-------- end dialog class --------

-------- sample code where I make use of the dialog --------

public static boolean uploadFolder(File folder, String targetUrl,
java.awt.Component component){
boolean success = true;

PostMethod filePost = new PostMethod(targetUrl);

filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
false);

TransferProgressDialog d = new
TransferProgressDialog(component, folder.getName());

try{
d.showDialog();

File[] files = folder.listFiles();
int numFiles = files.length;

Part[] parts = new Part[numFiles + 1];
parts[0] = new StringPart("folder_name", folder.getName());

for(int i=0; i<numFiles; i++){
parts[i+1] = new FilePart(files.getName(),
files);
}

filePost.setRequestEntity(new MultipartRequestEntity(parts,
filePost.getParams()));

HttpClient client = new HttpClient();

client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

int status = client.executeMethod(filePost);
if(status != HttpStatus.SC_OK){
success = false;
}
}catch(Exception ex){
success = false;
ex.printStackTrace();
}finally{
filePost.releaseConnection();
d.hideDialog();
return success;
}

}

-------- end sample code --------
 
I

IchBin

hello_world said:
Hi,

I've developed an applet which enables multiple file uploads via http
using HttpClient 3.0. During the upload process, I would like to
display a non-modal dialog box with some text and an animation
(basically a message - "uploading" - and an animated GIF). As soon as
upload is over, the dialog box should disappear.
[snip code]

-------- end sample code --------
Sounds like you want to use a splash screen. From what you describe it
sounds you need to separate the file upload into its own thread.

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

IchBin said:
hello_world said:
Hi,

I've developed an applet which enables multiple file uploads via http
using HttpClient 3.0. During the upload process, I would like to
display a non-modal dialog box with some text and an animation
(basically a message - "uploading" - and an animated GIF). As soon as
upload is over, the dialog box should disappear.
[snip code]

-------- end sample code --------
Sounds like you want to use a splash screen. From what you describe it
sounds you need to separate the file upload into its own thread.
Sorry, here are couple articles that will help. Or do a google for Java
Splash Screens

Java Tip 104: Make a splash with Swing
http://www.javaworld.com/javaworld/javatips/jw-javatip104.html

Java Practices: Splash screen
http://www.javapractices.com/Topic149.cjp

How to do a fast Splash Screen in Java
http://www.randelshofer.ch/oop/javasplash/javasplash.html

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
H

hello_world

Thanks for the prompt response! That's exactly the type of effect I'm
trying to achieve. I'll proceed accordingly...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top