repainting the whole frame??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: repainting the whole frame??

  1. #1
    Join Date
    Oct 2004
    Posts
    15

    repainting the whole frame??

    I have a JOptionPane that pops up and asks the user to enter a filename.

    i need help with Two questions:

    1) my JOptionPane:

    String inputValue = JOptionPane.showInputDialog("Please input fileame (including extension)");
    filename = inputValue;

    passes the entered filename to my global variable "filename". This variable (filename) is used to paint the image onto a JIcon:

    ImageIcon icon = new ImageIcon(filename);
    JLabel background = new JLabel(icon);
    mapPanel.add(background);


    What do i need to do to get the loaded image update? Ithough i would just be able to do a :

    mapPanel.repaint()

    but it doesnt work because it only ever calls the:

    this.getContentPane().add(mapPanel, BorderLayout.CENTER);

    once. So how do i get it to repaint the whole frame again? this time including the newly updated filename???



    2)What do i need to do to add browse functionality to the JOptionPane???

  2. #2
    Join Date
    Sep 2004
    Posts
    223
    for your first question, after your code:

    Code:
    ImageIcon icon = new ImageIcon(filename);
    JLabel background = new JLabel(icon);
    mapPanel.add(background);
    try just adding the line:

    Code:
    repaint();
    just like that, nothin before it. That should do it.


    as for the second question you need to use the JFileChooser class. Here is an example from sun:

    The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:
    Code:
        JFileChooser chooser = new JFileChooser();
        // Note: source for ExampleFileFilter can be found in FileChooserDemo,
        // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
        ExampleFileFilter filter = new ExampleFileFilter();
        filter.addExtension("jpg");
        filter.addExtension("gif");
        filter.setDescription("JPG & GIF Images");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(parent);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           System.out.println("You chose to open this file: " +
                chooser.getSelectedFile().getName());
        }
    A kram a day keeps the doctor......guessing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center