Show an image on a JPanel with GridbagLayout

Hi All,
I have a serious problem: I'm building a GUI with following characteristics:
JFrame in which is inserted a JPanel. This Jpanel has a GridBagLayout.
In this JPanel are shown diefferent Component types (JTextField, JTextArea, JLabel and so on).
I would show an image on a apecific free part of this JPanel, without move actual components distribution.
Now the image is automatically reduced to be insert in a "line/column" according to GridBagLayout, but I don't want this!!!!
Help me!!!
Thanks in advance!

Hello,
You are on Captivate 4, that is a pity, because I did blog a while ago about hiding and showing objects but in Captivate 5. However the principles are the same: you can not show an object unless the action is executed on the slide where the object sits. Hope this makes sense?
So in your case, you should perhaps create a user variable, originally=0 and that you change to 1 when the click box is clicked in the action on the slide with the click box. And then you will need a conditional action, to be triggered on entering the slide where the image is. This action checks the value of the user variable, if it is 0 the image will be hidden, if it is 1 it will be shown.
Here is the link to my blog post:
Playing Hide-and-Seek with Captivate objects
I'm willing to help you if you cannot work it out.
Lilybiri

Similar Messages

  • Showing an image in a JPanel

    Hi all!
    I'm developing an applet that shows an image in a JPanel when it is clicked. The problem is that when the code that shows the image is placed in the mouseClicked() method, nothing happens...
    Any idea would be appreciated.
    Thanks in advance.
    Applet's code:
    package test;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.*;
    public class ImageMouseClick extends JApplet implements MouseListener{
      private boolean isStandalone = false;
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      GridBagLayout gridBagLayout1 = new GridBagLayout();
      BufferedImage bufi;
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      //Construct the applet
      public ImageMouseClick() {
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      //Component initialization
      private void jbInit() throws Exception {
        this.getContentPane().setBackground(Color.white);
        this.setSize(new Dimension(400,300));
        jPanel1.setLayout(gridBagLayout1);
        jPanel2.setBackground(Color.white);
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
        jPanel1.add(jPanel2,  new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
                ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(72, 82, 81, 100), 208, 137));
        jPanel2.addMouseListener(this);
        File f = new File("/home/***/myimage.gif");
        try {
          bufi = ImageIO.read(f);
        } catch (IOException ioe){
          System.out.println("IO Error");
      public void mouseClicked(MouseEvent me) {
        //Add image to JPanel2
         JLabel showWorld = new JLabel(new ImageIcon(bufi));
        jPanel2.add(showWorld);
        jPanel2.setVisible(true);
        System.out.println("Click!");
      public void mousePressed(MouseEvent me) {
      public void mouseExited(MouseEvent me) {
      public void mouseEntered(MouseEvent me) {
      public void mouseReleased(MouseEvent me) {
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      //static initializer for setting look & feel
      static {
        try {
          //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        catch(Exception e) {
    }

    In the event loop (handling the mouse click) redrawing is not done.
    You could try to add a showWorld.repaint(100L); for a later repaint.
    A more general solution is SwingUtilities.invokeLater(...);; for that better read the javadoc.

  • How to show an image(jpg/gif) on a JTabbedPanel

    Hi
    I tried to show an image on a JPanel of a JTabbedPanel.
    I the only way to show it for some time was this:
    in the StateChangedListener I use drawImage when the selected panel is teh one I want to draw the image at.
    Tracing code makes the panel show, burt when I step
    all the way up, the panel will be repainted without my image.
    I use mediatracker to get the image loaded.
    Any Idea
    Hanns

    JTabbedPane has components as its tabs. Using a JPanel is not mandatory. Try using a JLabel instead with an Icon (use ImageIcon) in it.
    JTabbedPane tabbed = new JTabbedPane();
    tabbed.addTab(
        "my image panel",
        new JLabel( new ImageIcon( "images/MyIcon.gif" ) )
    );if your were referring to the image of the little tabs, use this:
    JTabbedPane tabbed = new JTabbedPane();
    tabbed.addTab(
        "my tab",
        new ImageIcon( "images/MyImage.gif" ),
        myPanel // instance of Component, can be a JPanel or any JComponent you want.
    );

  • Show an Image

    Hello!
    My question is probably stupid, but I've got some problems to show an image in a jPanel (or others Containers).
    There are a lot of tutorials for showing an image in applets, but it's difficult to have good explanations for an application.
    I know I should use GetImage and Toolkit but I don't know how.
    I'm sure it's quite simple, so
    Can anyone give me some code samples?
    Thank you for your replies.

    hi,
    you can create a jlabel and add an image to that and then place the jlabel into a jpanel.
    import javax.swing.*;
    import java.awt.event.*;
    class ShowImage extends JFrame {
         JPanel panel = new JPanel();
         JLabel label = new JLabel(new ImageIcon("add.gif"));
         public static void main(String args[]) {
              ShowImage obj = new ShowImage();
              obj.display();
         void display() {
              panel.add(label);
              getContentPane().add(panel);
              setSize(100,100);
              addWindowListener(new WindowHandler());
              setVisible(true);
         class WindowHandler extends WindowAdapter {
              public void windowClosing(WindowEvent e) {
                   dispose();
    }

  • JPanel with Image just doesn't want to show

    Hello,
    i am trying to create a JPanel with a JLabel to which i assign an ImageIcon, but for some reason the JPanel seems not to appear in my JFrame.
    Here's the code: private void jbInit() throws Exception
        NumberListener numListener = new NumberListener();
        frame = new JFrame();
        frame.setTitle("Error Manager");
        frame.setLayout(new GridBagLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        numberList = new JList(numbers);
        numberList.addListSelectionListener(numListener);
        numberList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane listScroller = new JScrollPane(numberList);
        listScroller.setPreferredSize(new Dimension(250, 80));
        frame.getContentPane().add(listScroller, gbc);
        imgPanel = new JPanel();
        imgPanel.setSize(300, 250);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image img = toolkit.createImage("Somepic.png");
        imgPanel.add(new JLabel(new ImageIcon(img)));
        gbc.gridx = 1;
        gbc.gridy = 0;
        frame.getContentPane().add(imgPanel, gbc);
        frame.pack();
        frame.setVisible(true);
      }

    Sorry forgot to close the code tags...
    private void jbInit() throws Exception
        NumberListener numListener = new NumberListener();
        frame = new JFrame();
        frame.setTitle("Error Manager");
        frame.setLayout(new GridBagLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridx = 0;
        gbc.gridy = 0;
        numberList = new JList(numbers);
        numberList.addListSelectionListener(numListener);
        numberList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane listScroller = new JScrollPane(numberList);
        listScroller.setPreferredSize(new Dimension(250, 80));
        frame.getContentPane().add(listScroller, gbc);
        imgPanel = new JPanel();
        imgPanel.setSize(300, 250);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image img = toolkit.createImage("1_Alpinweiss_III.png");
        imgPanel.add(new JLabel(new ImageIcon(img)));
        gbc.gridx = 1;
        gbc.gridy = 0;
        frame.getContentPane().add(imgPanel, gbc);
        frame.pack();
        frame.setVisible(true);
      }

  • Upon starting Mac shows image of a folder with ? inside, any help appreciated, thanks.

    As stated above, when I start Mac it shows a white screen with an image of a folder with a ? inside it.
    I have shut it down by holding the power button then pulled the power cord waited 10mins and restarted for the same result.
    Any help would be great.

    Cheers for the info Allan.
    I unfortunately do not have a back up.  It is in the hands of the repairer now, fingers crossed they can save my stuff.
    FYI, i'll be backing up in future.

  • I forgot my admin password for my macbook and my macbook doesnt allowme to go on single user or boot up in safe mode or boot up with the option key all it does is show a image of a globe blinking everytime i try to do something

    please people help me i brought this macbook from a friend and now its ****** up its a macbook late 2006 and it dosesnt allow me to do anything everytime i click on a key to go on single user terminal or boot up cd or run on safe mode it shows a image of a globe(earth)

    Somehow the HDD is screwed up. Data saving issue is not directly Toshiba related issue and before you spend time here discussing about such things I recommend you to ask someone with good PC knowledge what can be done about data saving.
    When the HDD is in the notebook again start notebook as first step set BIOS to default settings.
    After doing this install recovery image. After doing this you will have clean preinstalled OS and everything should work properly again.
    I hope you will be able to do this using HDD recovery option.
    How to do this you can find on http://aps2.toshiba-tro.de/kb0/HTD1303440001R01.htm
    Have you maybe created recovery discs?

  • I've been using LR with my Nikon D3200 for a year or so. Shooting in RAW/NEF no issues with import etc until I updated LR and now I can't get LR to allow me to select when I try to import. It does show the images but they're grayed out and not able to be

    I've been using LR with my Nikon D3200 for a year or so. Shooting in RAW/NEF no issues with import etc until I updated LR and now I can't get LR to allow me to select when I try to import. It does show the images but they're grayed out and not able to be selected. Any thoughts? TIA

    Greyed imaged in the Import dialog box mean you have already imported the photos into Lightroom, so there is no need and no benefit to importing them a second time.
    Just go to the Library module, search for the desired photos, and resume working on these photos.

  • How to Show images in mail box with java mail??????????

    Hello everyone,
    Iam sending mail using java, my mail format consisit of colored text and images,that should be diplsyed to reciever in mail box,my code is working fine reciever gets mail in inbox but problem is when we recieve mail like that images doesnot show up in the mail automaticaly,when i click on show images link in my mail box only then images become visible,i tested my mail in gmail,rediff and yahoo and in all cases i have to mannually click on "show images" link to view images that i sent with my mail,why so? is this due to security reasons in mailbox??? can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.
    Please help.
    Thanks.

    anie wrote:
    can i write such code that can overcome this problem i.e my images shows directly in anymailbox without clicking on showimages link.No. That's a security function of the browser, and not something you can control.
    On another note, please refrain from posting unnecessary, excessive punctuation. It only clutters up your message, which isn't a good thing. Thanks!
    ~

  • Why is my iphone 4 (Verizon) not showing images? turns on with a black screen no apple logo.

    the phone turns on, but shows no images just a lit up black sceen. plzzzzzzzzzzzzzzzzzzzz help me!

    They better huh?
    I'm sure Apple is shaking in their boots.
    No such problem with my iPhone which I connect with a number of wi-fi networks.
    If the same problem with any other wi-fi network besides your own and no change after resetting network settings and/or after restoring the iPhone as a new iPhone or not from the backup, the iPhone has a hardware problem.
    If the problem is with your wi-fi network only - no problem with any other wi-fi network besides your own, the problem is not with the iPhone.

  • Grabbing images at 60 hz with IMAQ grabber and showing them

    Hi all,
    I'm programming an application where I 've to show and do some realtime (60hz) calculations on a thermal image coming from a thermal camera through GigE
    At the beginning, the program works fast, good framerates, but after a while, framerates start dropping, and eventually will stop.
    When I remove the Imaq image viewer (right, I do not work with the external windraw), the program doesn't slow down, but than I haven't any image anymore
    I tried with synchronous displays etc, but nothing helps.
    Any idea's? 
    in annex, you have a screenshot of a part of the program.
    Thanks
    Attachments:
    ni screenshot.png ‏24 KB

    Hello Biebel,
    Can you share your actual VI's/code (including subVI's)?
    It would be interesting to see what you're doing in parallel in your timed loop.
    Are you perhaps building any arrays in parallel or in other parts of your VI?
    Is the memory and/or CPU usage of the program increasing with time?
    Are there any other programs running in parallel?
    What do you exactly mean with "after a while"?
    Is this 5 seconds or rather several minutes or hours?
    Decreasing the update rate could be a good idea, but in this case I think it could still cause issues.
    Especially if your frame rate gradually drops, this could indicate a memory leak.
    Kind Regards,
    Thierry C - Applications Engineering Specialist Northern European Region - National Instruments
    CLD, CTA
    If someone helped you, let them know. Mark as solved and/or give a kudo.

  • Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Hi Ciaran19,
    Are you sending files from the Adobe Send interface, Adobe Reader, or the Outlook plug-in?
    Have you checked to see whether the files that you're sending appear in the Recent Files/Sent Files list when you're logged on to https://cloud.acrobat.com? (It could be that they're uploading, but not being sent.)
    It would also be worthwhile to send the files in smaller batches, to see whether a particular file or files is problematic, and causing the error.
    Please let us know how it goes. If you're still having trouble, please let us know where you're sending from, and whether you're able to send the files in smaller batches. It would also be helpful to know the exact error message that you're receiving.
    Best,
    Sara

  • Why does some images saved on memory card show up as a little icon with lightning bolt through it

    I been saving images on memory card.. well as of lately some images have a icon with a lightening bolt on it..and images are lost

    There is a problem with the SD card.  Reboot your phone and see if the problem comes back. If the problem comes back un-mount and remove the card and see if a computer can read the card.  If the computer can read it then move all the photos to the computer then reformat the card in the phone. Put the reformatted card back in the phone and take a picture.  If the problem persists then the card is corrupted in some way.  This is more common than you would think especially if you have a galaxy S3 and use SanDisk cards. I would try a new card from a different manufacturer.

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • Fill space in panel with GridBagLayout

    Hello,
    I have a class that extends JPanel and uses a GridBagLayout.
    I would like the contents of this panel to occupy the whole available space.
    However, I don't find how to do it with GridBagLayout (I know this is automatically done with BorderLayout but I want to use GridBagLayout for organizing internal components).
    I have this small program to show the problem.
    In this example, how could the button fill all the available space with GridBagLayout?
    Note that setting GridBagConstraints fill to BOTH doesn't solve the issue.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.LayoutManager;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestBlankSpace {
        private static int x = 200;
        public static void main(String[] args) {
         testPanel(new BorderLayout(), BorderLayout.CENTER);
         testPanel(new GridBagLayout(), createGridBagConstraints());
        private static void testPanel(LayoutManager manager, Object constraints) {
         JPanel panel = new JPanel(manager);
         JButton button = new JButton("button");
         button.setBackground(Color.ORANGE);
         panel.setBackground(Color.WHITE);
         panel.add(button, constraints);
         JFrame window = new JFrame("Test Panels");
         window.add(panel);
         window.setLocation(x, 200);
         window.setSize(400, 300);
         window.setVisible(true);
         window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         x += 400;
        private static GridBagConstraints createGridBagConstraints() {
         GridBagConstraints c = new GridBagConstraints();
         c.fill = GridBagConstraints.BOTH;
         return c;
    }Thank you

    Hi,
    For better understanding the grid bag layout read this tutorial :
    [http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html|http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html]
    Olek

Maybe you are looking for