2 swing questions: JScrollPane and displaying pictures

I'm building a GUI for a toy application I have written, I have two questions:
1-The main window is inherited from JFrame, There is a JTabbedPane attached to it, and a JPanel as the first tab of the tabbed pane. There are so many jcomponents in this JPanel, this makes it too big for small resolution computers (below 1024 * 768), I would like to add this JPanel to a JScrollPane to make it behave like a text area, I've done it but it didn't work, obviously there is something I'm missing.
2-My application calls another program to create some images at runtime which will be displayed in the other tabs, after calling the program and creating the image, I get the filename of the image. What is the best way to display this image?
I have tried JLabel's but they don't update their pictures for some reason after it has been changed.
Thanx in advance.

Updated and tested code, hopefully this will help.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class ImagePanel extends JPanel {
  private String imageFilename = null;
  private Image image = null;
  private Toolkit toolkit = null;
  public ImagePanel() {
    super();
    toolkit = Toolkit.getDefaultToolkit();
  public void setImageFilename(String filename) {
    imageFilename = filename;
    try {
      image = toolkit.createImage(imageFilename);
      setPreferredSize(new Dimension(image.getWidth(this), image.getHeight(this)));
      repaint();
    } catch (Exception e) {
      e.printStackTrace();
      imageFilename = null;
      image = null;
  public Dimension getPreferredSize() {
       if (image == null) return new Dimension(0, 0);
       else return new Dimension(image.getWidth(this), image.getHeight(this));
  protected void paintComponent(Graphics g) {
       Insets insets = getInsets();
       g.setColor(Color.white);
       g.fillRect(0,0, insets.left + getWidth(), insets.top + getHeight());
    if (image != null) {
      g.drawImage(image, insets.top, insets.left, this);
  public void reloadImage() {
       if (imageFilename != null) {
      try {
        image = toolkit.createImage(imageFilename);
        repaint();
      } catch (Exception e) {
        imageFilename = null;
        image = null;
  public static void main(String args[]) {
       JFrame frame = new JFrame();
       frame.addWindowListener(
            new WindowAdapter() {
                 public void windowClosing(WindowEvent we) {
                      System.exit(0);     
       frame.setSize(600, 400);
       JPanel parentPanel = new JPanel();
       parentPanel.setLayout(new GridLayout(1,1));
       JTabbedPane tabPane = new JTabbedPane();
       ImagePanel imagePanel = new ImagePanel();
       JScrollPane scrollPane = new JScrollPane(imagePanel);
       imagePanel.setImageFilename("C:\\dell\\drivers\\R27748\\mrmfiles\\image015.jpg");
       parentPanel.add(scrollPane);
       tabPane.addTab("Tab 1", parentPanel);
       frame.getContentPane().add(tabPane);
       frame.show();
}

Similar Messages

  • Store, Retrieve and Display picture or video to/from DB2 using JDBC

    I need an idea for implementing the"Store, Retrieve, Display Image/Video" concept in JDBC. My Database is DB2. I could not get proper info from google.
    Thanks and Regards
    Muthukris Bala

    Muthukris wrote:
    I need an idea for implementing the"Store, Retrieve, Display Image/Video" concept in JDBC. My Database is DB2. I could not get proper info from google.
    1. Figure out how to display image/video
    2. Figure out how to encode/decode a image/video into a byte array
    3. Design a database suitable for your application that stores blobs
    4. Figure out how to use JDBC to store/retrieve blobs via byte arrays.
    Steps 1 and 2 have nothing to do with this forum (nor GUI code). There is at least on forum on this site that deals with questions about that.
    Steps 3 is only somewhat related to this forum. A DB2 forum would be best.
    Step 4 is the only part of this that is specific to this forum. And if you have not used any JDBC then you first start with the tutorial or some other suitable method to learn how JDBC works before attempting blobs.

  • Two basic xcode questions (tabs and displaying members)

    I have two questions about xcode that are most likely answered easily:
    1. Is there a way to set it so that selecting a block of text and hitting tab or shift tab will indent it instead of replacing it with a tab? I know that i can right click and do move right, but that is pretty irritating to do on a regular basis.
    2. How do I get xcode to display members of classes and structs when I am typing? For example if I type 'var->' I want it to pop up a list of available members that belong to var for me to choose from. Or if I type 'function(' i want it to list what the parameters are that function is expecting.

    I don't think that anyone much gives a flying fsck what "features" are available; unless that person is trying to "sell" something to you.
    Of course, I assumed your standards were based on what Micro$hite offers you. Why should that be a standard?
    If you want similar features, you will have to use a proprietary Apple API. Believe me, you can get it. But you cannot inspect MFC from inside Apple's IDE.
    I'm sorry, I don't really intend my remarks to be harsh. It just astonishes me when people don't realize that these folks are not in business to HELP YOU but are in business to MAKE MONEY.
    I'm not even saying this is wrong. I'm just saying, you should not be astonished.

  • Upload and display picture on mug from website

    I need to be able to upload pictures to my website and then
    show that picture on a mug on the website automatically. Can anyone
    show me where to start? TY

    "jkjkljkl;kljkljl4q35" <[email protected]>
    wrote in message news:ebnm5f$90a$[email protected]..
    >I need to be able to upload pictures to my website and
    then show that picture on a mug on the website automatically. Can
    anyone
    >show me where to start? TY
    Unfortunately, Flash only allows rotating and width/height
    mods to bitmaps. It doesn't let you distort bitmaps in a way that
    would
    make it appear to wrap around the cup. there is a way to
    break apart a bitmap into thousands of vectors that can be shoved
    around
    but the file size would jump up dramatically and you would
    have a tough time making it follow a distortion shape. Maybe
    someone
    else can think of another way to do it. Maybe the newest
    Flash 8 program has other capabilities that I haven't heard about.
    luck,
    tralfaz

  • Loading And Displaying image From MYSQL

    Hello, How can I load and display picture stored into a MYSQL database in a Swing GUI using for example JLable component.

    establish a connection to ur sql, n
    retireve the record with the images or image url in the db.
    and then load it to a Image icon and set it to a JLabel.

  • Open picture files and display in fullscreen slideshow?

    I'm hoping for some help as I'm very new to LabView and quite lost....
    I have a directory with many picture files (too many to put them all in
    a powerpoint slideshow) and i want to open them one by one and display
    them full screen with no border around them (not in a picture box, but
    as displayed in a powerpoint slideshow). 
    I'm trying to use activeX to call the default "Preview" application for
    windows, (which is able to run a slideshow when opened manually from
    the directory).  In the LabView VI, when the slideshow runs, it
    takes over the full screen, as it should, however, the images are not
    shown.  The screen says "no preview available".  I've messed
    around with it a lot and just can't get it to work. 
    Any other application or any other way of displaying the images full
    screen would be acceptable, if you know of any.  I've also tried
    the adobe acrobat browser 7.0, which has a full screen option, but i
    can't seem to get that one to work either.  Attached is a copy of
    my code.
    Any help or advice would be much appreciated.  Thanx.
    -dave
    Attachments:
    picture viewer2.vi ‏75 KB

    The easiest would be to set the window not to have toolbars, scrollbars, etc. and to fill the entire screen and to scale all objects with the windows (these can be found in 2 pages of the File>>VI Properties dialog). If you resize your FP so your picture indicators fills it before doing this then any resizing of the window will resize the indicator as well. You can then use the Zoom property to enlarge the picture. To calculate how much to zoom you can divide the size of the picture by the Application>>Display>>Primary Workspace property.
    Another option would be to use property nodes to change the Draw Area Size of the picture to fill the screen and to resize the picture itself using something similar to the method demonstrated here.
    Try to take over the world!

  • Question marks on my pictures and diagonal lines down the page

    My site is web.mac.com/jkmerchant. Last night I changed a couple page names, re-ordered them, added some photos, added a blog entry and updated the text, added a new picture on the welcome page and replaced a picture on the welcome page. Ever since then, my changes publish (with an error) and I can see the updates via my browser, but almost all of my pages now have question marks on the pictures and diagonal frame type lines down the page. I appreciate any suggestions to fix this problem. I've verified the question marks are appearing in IE using a windows computer and Safari (as well as in iWeb) on a Mac.

    Kevin ~ If you haven't already tried this, it may help — in iWeb do File > Publish All to MobileMe. If not, +"A lot of problems can be solved simply by..."+ Read more in the "Fix iWeb" section here:
    http://www.iwebformusicians.com/WebMusic/iWebTips.html
    Also it may be better to access your site via:
    http://web.me.com/jkmerchant
    ...rather than:
    http://web.mac.com/jkmerchant

  • Display picture and video in the same indicator

    Hi,
    I want to use an indictor to display picture as well as videos( not simultanously). I trid but stuck. Need guidance to complete it. Thank you. 
    Attachments:
    SPEECH TO SIGN LANGUAGE TRANSLATOR 2011.zip ‏37 KB
    New folder.zip ‏2320 KB

    Unfortunately that's how it works. If you have a 3rd party editor you could add the text to the picture before adding it to the calendar. Put in a feature request at http://www.apple.com/feedback/iphoto.html.
    Do you Twango?
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • My ipod touch 4g will not connect to tv, will not display picture. keep getting a message saying this accessory is not supported by ipod touch, what do ido to make this work and get rid of the message i keep getting?

    My ipod touch 4g 5.0.1 will not connect to tv, will not display picture. Also keep getting a message sayin this accesory is not supported with ipod touch. How do i get this to work and stop getting this message? Please help.

    - What cable re you using? Digitasl, VGA, composit, componet and who made it?
    - TV out only works with apps that support it.  It does not morror the iPod's screen
    - Have tired another TV or other display?

  • BBM display picture is blurry! Can not rotate and zoom. Update please

    Hi.. Please help me.. I just bought blackberry q10 but I really don't like how the BBM works. How to fix a blurry display picture on bbm? I'm using blackberry for a long time and I need to share and update my pictures to my family and my friends which are mostly live in another country... Please please fix it.... It can't rotate and zoom too... I tried all pictures to put on my display picture but still blur.. Even the picture I took from Q10 itself which is have 8mp but still blur too.. my friend asked me why my pictures always blur like i took pics with a bad quality camera.. It's not cool thank you before

    This seems to be an issue for some but not others and I haven't yet seen a resolution. It only happens with display pictures. If you send a picture via BBM it should work fine.
    1. Please thank those who help you by clicking the "Like" button at the bottom of the post that helped you.
    2. If your issue has been solved, please resolve it by marking the post "Solution?" which solved it for you!

  • Drag and Drop not working/MSN display picture cannot find Iphoto

    I had the ilife '06 and I was able to drag a photo from (lets say) facebook and drop it into iphoto. I am unable to do this in the ilife '09 version. In addition, when I try to change my display picture in msn i cannot click on iphoto only photobooth is highlighted, please help!!!

    Welcome to the Apple Discussions.
    I was able to drag a photo from (lets say) facebook and drop it into iphoto. I am unable to do this in the ilife '09 version.
    What browser are you using? Safari? If so, right click on the pic and choose 'Add to iPhoto.
    In addition, when I try to change my display picture in msn i cannot click on iphoto
    There are many, many ways to access your files in iPhoto:
    *For Users of 10.5 and later*
    You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Command-Click for selecting multiple pics.
    Uploaded with plasq's Skitch!
    You can access the Library from the New Message Window in Mail:
    Uploaded with plasq's Skitch!
    *For users of 10.4 and later* ...
    Many internet sites such as Flickr and SmugMug have plug-ins for accessing the iPhoto Library. If the site you want to use doesn’t then some, one or any of these will also work:
    To upload to a site that does not have an iPhoto Export Plug-in the recommended way is to Select the Pic in the iPhoto Window and go File -> Export and export the pic to the desktop, then upload from there. After the upload you can trash the pic on the desktop. It's only a copy and your original is safe in iPhoto.
    This is also true for emailing with Web-based services. However, if you're using Gmail you can use iPhoto2GMail
    If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto.
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    *If you want to access the files with iPhoto not running*:
    For users of 10.6 and later:
    You can download a free Services component from MacOSXAutomation which will give you access to the iPhoto Library from your Services Menu. Using the Services Preference Pane you can even create a keyboard shortcut for it.
    For Users of 10.4 and later:
    Create a Media Browser using Automator (takes about 10 seconds) or use this free utility Karelia iMedia Browser
    Other options include:
    1. *Drag and Drop*: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    2. *File -> Export*: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    3. *Show File*: Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.
    Regards
    TD

  • HT1721 My computer turns on and displays a folder icon with a question mark in it

    What should i do if my computer's screen is grey and displays a folder icon with a question mark in it?

    http://support.apple.com/kb/TS1440
    Not covered in the article is a possible hard drive failure.

  • Have new mini.  When starting 1st time, it stop and displays a picture to push start button on WiFi keyboard.  I have USB Apple Kekboard.  Can't get pass the display to Startup Assist.

    Have new mini.  When starting 1st time, it stop and displays a picture to push start button on WiFi keyboard.  I have USB Apple Kekboard.  How can I get pass the display to Startup Assist?

    Have new mini.  When starting 1st time, it stop and displays a picture to push start button on WiFi keyboard.  I have USB Apple Kekboard.  How can I get pass the display to Startup Assist?

  • TS3276 mail messages often fail to display pictures and graphics?

    i have a problem with some mail messages in that they do not display picture and graphics. i have Flip4Mac installed and have a late model Macbook Air 13 inch running Mavericks

    Assuming that your operating systems are as steated in your signatures, you both may find it helpful to remove the account from Mail Preferences/Accounts and then set it up again following the instructions here:
    Entering iCloud email settings manually in Snow Leopard or Leopard

  • How to drag and drop a picture at run time in a window displaying pictures?

    How to drag and drop a picture at run time in a window displaying pictures on the front panel. The main thing is that the window is displaying frames continuously?

    vivman,
    So from your description you have a picture control where you've already created an image and you'd like to drag an image around inside of the picture control. This can be done although it is going to take a significant amount of research and programming on your behalf. You can use the drag event in the event handler to find out when the drag occurs and where the cursor is. Then edit the picture as you move your mouse so that when you drop the picture gets updated.
    The even structure is a somewhat advanced topic and the drag and drop feature is one of the more advanced uses of this structure. I would search the example finder (help>>find examples) for "event" and "drag" to see how to use these events. Also you'll want to look at the examples for the picture control.
    Sounds like a cool project! Check out Darren's Weekly Nugget 10/30/2006 this topic (http://forums.ni.com/ni/board/message?board.id=170&message.id=212920). It might prove useful.
    Good luck!
    Chris C
    Chris Cilino
    National Instruments
    LabVIEW Product Marketing Manager
    Certified LabVIEW Architect

Maybe you are looking for

  • Stock in transit on a particular date

    Hi Gurus, Can you please tell me how to take stock in transit on a particular date (past date and not on current date). Thanks & Best regards

  • How do I place a SubReport on the last page of a report?

    Post Author: KPichelman CA Forum: Crystal Reports I am using CR 9.0 and C# to create a report.  Now I need to place a subreport (a signature box) on the last page of the report and I seem to be having difficulties.  I will not know the number of page

  • Starting OBIEE 11g

    Hi, I have installed OBIEE 11g. then i tried to login by following. -> start BI services -> entered the weblogic user name and password -> then iam getting as wls.alive and keep blinking It's not leading to login page. Is there any error caused this?

  • Why does Itunes keep opening every 30 seconds?

    When I have Itunes minimized on my toolbar it keeps popping up in front of all my other windows and programs about every 30 seconds. It is making it impossible to listen to music in Itunes while I play a game or work on my writing. Any help would be

  • Download of free trial of Adobe X Pro

    I am attempting to download from Acrobat.com their free trial version of Adobe X Pro, but everytime I hit the "download" button, nothing happens.