Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

JDialog does not display properly

Thread view: 
hello_world - 16 Jan 2006 08:20 GMT
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[i].getName(),
files[i]);
           }

           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 --------
IchBin - 16 Jan 2006 08:32 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> (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.

Signature

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-)

IchBin - 16 Jan 2006 08:38 GMT
>> Hi,
>>
[quoted text clipped - 10 lines]
> 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-)
hello_world - 16 Jan 2006 09:01 GMT
Thanks for the prompt response! That's exactly the type of effect I'm
trying to achieve. I'll proceed accordingly...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.