FileChooser And ProgressBar

Dear visitor:
thanks for caring my problems:)
well,i don' t know how to show a FileChooser in the specific mode i want:the save mode and open mode,and when i select a file in a file chooser,how could i add
an action listener on the "save" button or the "open" button to save or open a file when i click the button.
the following question is how to link the progress bar to a thread.for example,
i am connecting a database or loading an image,how to use the progress bar to show
exactly how much work has been done,for example,how many percents of the picture has been loaded
thanks for your help!
zhile:)

hi zhile!
well, you don't need to put an actionlistener on the save or open button of your filechooser...
you just use sample code:
JFileChooser fileChooser = new JFileChooser();
int returnVal = fileChooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
//in case you select a file
File file = fileChooser.getSelectedFile();
else
//selection a file was cancelled
or didn't i understand you correctly?
regards,
majandrah

Similar Messages

  • FileChooser and Directory Issue

    I am using FileChooser and I want user to select only directory.
    So for that i have chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    I am having the problem like when user selects the directory C:\docs\api.
    But when I am calling the File newDir = chooser.getCurrentDirectory();
    it is taking as only C:\docs , but I want the C:\docs\api.
    How I can achive this?

    If you don't get any useful replies soon, then your best bet here is to show us your code. We don't want to see all of it, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem, in other words, an SSCCE (Short, Self Contained, Correct (Compilable), Example). For more info on SSCCEs please look here:
    [http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html]
    Remember, the code must be compilable and runnable for many of us to be able to understand it fully.
    Good luck!

  • Drag drop and ProgressBar cancel button

    Hi,
    I have a class that extends CDragDropTargetFlavorHelper, during ProcessDragDropCommand I want to show a ProgressBar (the code that does this is actually in another, model only, plugin - might be significant), however, though the progress bar shows the cancel button doesn't.  Unless I delay the processing until after the drop is complete by scheduling the command - if I either process the command or schedule and process scheduled commands the cancel button doesn't show.
    Scheduling the command gives a bit of a delay to the user (even with highest priority) and also no ability to feedback 'drop failed'.  So I'd like to:
    - preferably get the cancel button to show without scheduling the command
    - know immediately when a drop has been completed and process scheduled commands.
    Thanks in advance
    Ian

    Thanks Ned,
    I have since been continuing to research this and it would seem that implementing the HitTest could be the way to go. If anyone has any experience or advice to support this I would be grateful.
    Regards
    Chris

  • Problem with fixing pagerdeluxe and progressbar while using jsf-ibm.jar

    hi,
    I am having a jsf data table with <hx:pagerdeluxe> to navigate, and i am using (jsf-ibm-unknown-vers.jar) jar, this works fine. I need to insert a progress bar in my jsf and used <hx:progressBar> but this was not available in the old jar, So i upgraded my jar to jsf-ibm.jar when i ran this progress bar works fine but he pager deluxe shrinks and unable to navigate.. I am using jboss server .... Can any one help me out about regarding this. So that both works fine
    Thanks.
    Rakesh M

    This is not related to Sun JSF. You might have more luck if you ask component library specific questions at the website/forum/mailinglist of the component manfacturer.

  • URLloader and progressbar

    Hi!
    I need to log the bytes which are sent by URLloader, to show
    them in a progressbar, or simply to check the time it will take.
    I know that is possible to get the bytes received by
    URLloader, but I don't mind it; I need to log the sent bytes,
    because I'm sending long forms by URLloader, and I don't know how
    to check progress status while SENDING.
    Is it possible? Could it be possible in a future? I really
    need this feature.
    Thanks

    I have tried it, but It only prompts a message when form is
    sent, so I have to wait... 2 minutes before it's shown if I send a
    long form (is a file in a multipart form).
    In addition, It shows the "server answer totalbytes", not the
    SENT bytes.

  • Stausbar and progressbar

    how to bind the message or status in
    progressbar and statusbar while running
    or calling stored procedure .
    can any one may help,
    thanks
    pullareddy janapana
    null

    Excerpt from from code book "Java Thread Programming" which you can adjust to your situation:
    public class Notify {
    private Object proceedLock;
    private boolean okToProceed;
    public Notify() {
    proceedLock = new Object();
    okToProceed = false;
    public void waitToProceed() throws InterruptedException {
    synchronized(proceedLock) {
    while(okToProceed == false) {
    proceedLock.wait();
    public void proceed() {  //call when the first thread finished its work
    synchronized(proceedLock) {
    okToProceed = true;
    proceedLock.notifyAll();
    Also note, that I wrote you better solution for first time :updating of JProgressBar (as all swing comp.) should be done in event dispatching thread. When you use SwingUtilities.invoke() and invokeLater(), thread (i.e. event dispatching thread) is placed into queue thus waiting for previous task to be finished.
    Please read about it in
    http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html
    It is very important concept about multithreading and swing gui.

  • Threads and progressbar

    hello all,
    I am trying to display a window with an indeterminate progress bar while I am searching through files looking for a particular file. The problem is that when I display the window, the outline of it appears, but never fully displays.......what I attempted to do, was make the window implement runnable. Inside of the run method, I set a JProgressbar to indeterminate and set the window to visible. Right before the code that searches for the file, I created a new thread and gave it an instance of my window class, then called the start method of the thread.
    ex
    class window extends JFrame implements runnable{
    JProgressbar bar = new......
    public void run(){
    bar.setIndeterminate(true);
    this.setVisible(true);
    inside of the main class(which itself is a JFrame)
    Thread temp;
    window mywindow = new window()
    temp = new Thread(mywindow);
    temp.start();
    //searching code here
    mywindow.dispose();
    anybody have any suggestions why the window doesn't display???
    Thanks

    Have you tried it without making the Progress window a thread? Just try opening the window and them starting the search. If that fails, try making the search a separate thread. I would avoid making the window a thread. The swing classes have their own threads running in the background. One thing I found that helps keep windows from freezing is when you have to fire a long process resulting from an actionPerformed event you can do this without writing a lot of code:
    //normal
    actionPerformed(ActionEvent e)
       doSomething();
    //allows window to refresh
    actionPerformed(ActionEvent e)
        new Thread() {
           public void run() {
                doSomething();
        }.start();
    }

  • ButtonBar and ProgressBar all in one

    Anybody have any idea how this ButtonBar + ProgressBar type
    of component was created?
    (See the InsuriCorp example, second one down)
    http://www.adobe.com/devnet/flex/articles/fig_pt6_05.html
    It's really great looking but I'm really not sure how they
    went about it.
    What's the best way to approach this? Mabye a Flash skin, or
    a custom effect, or is there a really easy way that I'm just not
    seeing?

    Unfortunately, no.

  • TableViewer and ProgressBar

    I know it is probably not the right place for this request, but I try ;-)
    I'm testing SWT/JFace and I would like to render a progress bar in a cell of a table using TableViewer class (and not only the Table class).
    Any idea?
    Thx

    You're right in that you're wrong to post here. Check out www.eclipse.org and look for the fora there.
    -Mike Schwager

  • IE5 and progressbar

    I use Internet Explorer 5 and weblogic 5.1
              When i call JSP page , the jsp is load complete but the progress-bar of IE5
              is loading the page and it isn´t true, jsp page
              is load.
              May be can somebody explain that.
              Thanks.
              

    Excerpt from from code book "Java Thread Programming" which you can adjust to your situation:
    public class Notify {
    private Object proceedLock;
    private boolean okToProceed;
    public Notify() {
    proceedLock = new Object();
    okToProceed = false;
    public void waitToProceed() throws InterruptedException {
    synchronized(proceedLock) {
    while(okToProceed == false) {
    proceedLock.wait();
    public void proceed() {  //call when the first thread finished its work
    synchronized(proceedLock) {
    okToProceed = true;
    proceedLock.notifyAll();
    Also note, that I wrote you better solution for first time :updating of JProgressBar (as all swing comp.) should be done in event dispatching thread. When you use SwingUtilities.invoke() and invokeLater(), thread (i.e. event dispatching thread) is placed into queue thus waiting for previous task to be finished.
    Please read about it in
    http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html
    It is very important concept about multithreading and swing gui.

  • Help with component progressBar and Loader

    The progress bar doesn't work if the .swf movie that's being loaded is being loaded into another movie. If the loader is on the main stage it works fine both in testing and on the internet.
    For example, I created a parent movie and a child movie with a loader and progressBar. The child movie works perfectly by itself. If I load the child movie into the parent movie the progressBar doesn't work.
    I'm a designer not a programmer. Is there a fix for this?

    When using the Loader component, the progress-bar needs to be in the parent movie to work.

  • A query related to ProgressBar and its placing inside Container

    Hi ,
    I tried an example with  Flex3 ProgressBar .I am posting the scenario in which it was correct in one case and wrong in another case .
    Please tell me what  is wrong here in the wrong case :
    The Program is related to :
    I have button on click of that i will be loading the Image . There is no Button and its event Listener Mentioned here .
    Correct Approach :
    This works fine as the Image and ProgressBar are in the same Container called HBox
    <mx:HBox>
    <mx:Image id="image" autoload="false"/>
    <mx:ProgressBar id="MYPB" source="{image}"/>
    </mx:HBox>
    Wrong Approach :
    The below isn't working as i placed ProgressBar outside the container called as HBox
    <mx:HBox>
    <mx:Image id="image" autoload="false"/>
    </mx:HBox>
    <mx:ProgressBar id="MYPB" source="{image}"/>
    Please share your ideas as why this behaves this way .

    Hi Kiran.
    I don't think either of the approach is wrong , it no way effected by placing the ProgressBar inside a container or outside the container.
    Run the sample application below. It will load for both approaches.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
    <mx:Script>
            <![CDATA[
                public function loadImage1():void {
                  image1.load('assets/liazon_logo.png');
                public function loadImage2():void {
                  image2.load('assets/liazon_logo.png');
            ]]>
        </mx:Script>
    <mx:HBox>
      <mx:Image id="image1" autoLoad="false"/>
    </mx:HBox>
    <mx:ProgressBar id="MYPB1" source="{image1}"/>
    <mx:Button label="Load Image1" click="loadImage1()"/>
    <mx:HBox>
      <mx:Image id="image2" autoLoad="false"/>
      <mx:ProgressBar id="MYPB2" source="{image2}"/>
    </mx:HBox>
    <mx:Button label="Load Image2" click="loadImage2()"/>
    </mx:Application>
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • Problem with JPanel and JScrollBar

    I am having a few problems displaying a progress bar, it is called by the program when needed. The problem is the JFrame appears but no panel seems to be added to it and what app is in the background can be seen through it.
    The frame, panel and progressbar are all declared as global variables at the start of the program.
    I have tried using pack() and repaint() but not had any luck and not really sure how to proceed.
    Thanks in advance
    Aaron
       private void setupProgBar(String title)
          //sets up progress Jframe to contain progress bar
          progress.setTitle(title);
          progress.setMinimumSize(new Dimension(300,100));
          progress.setLocationRelativeTo(null);
          progress.setAlwaysOnTop(true);
          progressPanel.setLayout(new GridBagLayout());
          loadMedia.setIndeterminate(true);
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
          c.weighty = 0.5;
          c.gridx = 0;
          c.gridy = 0;
          progressPanel.add(loadMedia, c);
          progress.add(progressPanel);
          progress.setVisible(true);
       }

    It's clearly a concurrency issue. Please go through this tutorial:
    The Java&#8482; Tutorials: [Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html|The best way to learn!]
    db

  • How to include PJC and Java Beans in forms

    I have tried a lot to include java codes in my forms ..So I decide to start with ProgressBarPJC(cause it is tested and provided with demo) but I could not set implementation class of java bean object to
    oracle.forms.demos.ProgressBarPJC it does not accept it but it accept ProgressBar instead of ProgressBarPJC. I don't know why? I have made changes in Forms90_builder_classpath to access f90all.jar and progressbar.jar. I have Progressbar.class and progressbarpjc.classs both but i don't know how to set implementation class to ProgressBarPJC.
    don't you think there is lots of configuration and path setting to use any JPC or Jar in forms? I am totally confused with this integration.
    Please solve this matter
    Thanking you,
    Neeraj

    and even more information samples and step by step instructions are on the Java spotligh on the Forms Upgrade Center : http://otn.oracle.com/formsupgrade

  • Load, create, and save image as thumbnail

    Duke Dollars to earn ... :)
    Hi,
    I want to create a very simple jsp page where I can upload an image through the filechooser and display the uploaded image on the page. When hitting a save button I want to save the image as a thumbnail on the webserver.
    If anyone has suggestions on smooth, clever code that will do this for me, it will be highly appreciated. And answers with code will be awarded.
    Regards
    Malin

    see if this can help you out...
    import com.sun.image.codec.jpeg.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    public class Thumbnail {
    public static void main(String[] args) throws Exception {
    if (args.length != 5) {
    System.err.println("Usage: java Thumbnail inputFileName " +
    "outputFileName width height quality"); //quality 0-100
    System.exit(1);
    // load image from INFILE
    Image image = Toolkit.getDefaultToolkit().getImage(args[0]);
    MediaTracker mediaTracker = new MediaTracker(new Frame());
    mediaTracker.addImage(image, 0);
    mediaTracker.waitForID(0);
    // determine thumbnail size from WIDTH and HEIGHT
    int thumbWidth = Integer.parseInt(args[2]);
    int thumbHeight = Integer.parseInt(args[3]);
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth = image.getWidth(null);
    int imageHeight = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) {
    thumbHeight = (int)(thumbWidth / imageRatio);
    } else {
    thumbWidth = (int)(thumbHeight * imageRatio);
    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    BufferedImage thumbImage = new BufferedImage(thumbWidth,
    thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    // save thumbnail image to OUTFILE
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(args[1]));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.
    getDefaultJPEGEncodeParam(thumbImage);
    int quality = Integer.parseInt(args[4]);
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float)quality / 100.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);
    System.out.println("Done.");
    System.exit(0);

Maybe you are looking for