Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 17 of 17

Thread: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Hi all,

    I complete an interface and it does a good job for searching photo.
    However, I got a problem now with photos displayed on application interface.

    The problem here

    imageprogram.jpg

    The photo are not displayed 100% on the interface, it seems that the photos are covered by something.

    I think a reason may be the way I am organizing JPanel or something else wrong ???

    This is a complete code of interface class:

    PHP Code:
    /**
     * This class contains all interfaces and some event handling functions
     * 
     * @author Hung Vu Pham
     * @version 1, 3/12/2012
     * @version 2, 5/12/2012
     */
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.*;
    import javax.swing.Timer;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JMenuBar;
    import javax.swing.KeyStroke;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;

    import java.util.*;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.Random;

    import com.aetrion.flickr.*;        // For FlickrJ classes.
    import com.aetrion.flickr.photos.*;

    import java.io.*; //for writing and reading file

    public class testUserInterface1 extends JFrame implements ActionListener
    {
    /**
     * @param Declaring all components for user interface
     * @param Firslty, to declare components of menu such as
     * @param JMenuBar to create a menu bar
     * @param JMenu to create a menu on the menu bar such as menu File.
     * @param JMenuItem to create a submenu of the menu such as fExit is a submenu of menu File.
    */    
        
    private JMenuBar menuBar;
        private 
    JMenu filemenuhelp;
        private 
    JMenuItem fExitmUploadmRecentPhotomSearchhGuidehAuthor;
        private 
    JPanel upperPanelcenterPanelInforPanel,imgPanelrecentPhotoPanelsearchPhotoPanel;
        private 
    JLabel welcomelWelcomelAboutrecentPhotoTitlesearchTitle;
        
    /**
     * @param Declaring Image paths to use by ImageIcon
     * ImageIcon whatEverName = new ImageIcon("path to local pc","name of photo"); 
     * 
    */ 
        //Welcome Image
        
    ImageIcon iWelcome = new ImageIcon("IMAGE/flickr.jpg""Flickr Image");
        
    // Icon of Fairy Tail Team
        
    ImageIcon iAbout = new ImageIcon("IMAGE/FairyTail.jpg""Fairy Tail Team");
        
    // Icons for 5 areas on the earth.
        
    ImageIcon africa = new ImageIcon("IMAGE/Africa.jpg""Africa");
        
    ImageIcon asia = new ImageIcon("IMAGE/Asia.jpg""Asia");
        
    ImageIcon america = new ImageIcon("IMAGE/America.jpg""America");
        
    ImageIcon aus = new ImageIcon("IMAGE/Australia.jpg""Australia");
        
    ImageIcon eu = new ImageIcon("IMAGE/Europe.jpg""Australia");

    /**
     * @author Athina Ioannou 
     * @author Edited by Hung
     * @param this to declare all components that should be in Search Panel
     * @param JButton btnStart, btnExit.
     * @param JLabel lblSearch
     * @param JTextField txtSearch
     */
        
    private JButton btnStartbtnExitbtAfricabtAsiabtAmericabtEubtAus;
        private 
    JLabel lblSearch;
        private 
    JTextField txtSearch;
        private 
    JPanel sContent;
    /////////////////////////////////////////////////////////////

        
    private PhotoPanel pp;
        private 
    String keyWord;
        private 
    String photoUrl;
        private 
    PhotoFinder pf;
        private 
    Timer timer;
        private 
    ArrayList<PhotophotoList;
        private 
    String originalKeyWordoldKeyWord;

    /////////////////////////////////////////////////////////////

        
    public testUserInterface1()
        {
            
            
    //Add regular components to the window, using the default BorderLayout.
            
    Container contentPane getContentPane(); //the app window        
            // create upper panel to hold menu bar on the top of interface
            
    upperPanel = new JPanel();
            
    contentPane.add(upperPanelBorderLayout.NORTH);
            
    upperPanel.setLayout(new BorderLayout());
            
    // Create menu bar to hold menus and submenus
            
    menuBar = new JMenuBar();
            
    //add menu bar to the top of interface
            
    upperPanel.add(menuBar);      
                
            
    // Build File menu and its short-cut key
            //file = new JMenu ("File");        
            //file.setMnemonic(KeyEvent.VK_F);
            //file.getAccessibleContext().setAccessibleDescription(
             //   "File related operations");
            // Create a submenu for File menu and ist short-cut key
            
    fExit = new JMenuItem ("Exit"KeyEvent.VK_E);
            
    fExit.addActionListener(this);
            
    // add components of File menu
            //menuBar.add(file);
            //file.add(fExit);
            
            // Build  Menu menu and its short-cut key
            
    menu = new JMenu ("Menu");        
            
    menu.setMnemonic(KeyEvent.VK_M);
            
    menu.getAccessibleContext().setAccessibleDescription(
                
    "Menu related operations");
            
    // Create submenus for Menu menu and its short-cut key
            //mRecentPhoto = new JMenuItem ("Check Recent Photos", KeyEvent.VK_C);
            
    mSearch = new JMenuItem ("Search Photos"KeyEvent.VK_S);
            
    // add components of File menu
            
    menuBar.add(menu);
            
    //menu.add(mRecentPhoto);
            //mRecentPhoto.addActionListener(this);
            
    menu.add(mSearch);
            
    mSearch.addActionListener(this);
            
    menu.addSeparator();
            
    menu.add(fExit);       
            
            
    // Build  Help Menu and its short-cut key
            
    help = new JMenu ("Help");     
            
    help.setMnemonic(KeyEvent.VK_H);
            
    help.getAccessibleContext().setAccessibleDescription(
                
    "Help related operations");
            
    // Create submenus for Help Menu and their short-cut key
            
    hGuide = new JMenuItem ("Short-Cut Key Guide"KeyEvent.VK_S);
            
    hAuthor = new JMenuItem ("About Us"KeyEvent.VK_A);
            
    // add components of help menu
            
    menuBar.add(help);
            
    help.add(hGuide);
            
    hGuide.addActionListener(this);
            
    help.addSeparator();
            
    help.add(hAuthor); 
            
    hAuthor.addActionListener(this);
            
            
    // Build Center Panel which is stayed in the center of interface.
            
    centerPanel = new JPanel();
            
    centerPanel.setLayout (new FlowLayout());
            
    contentPane.add(centerPanelBorderLayout.CENTER);      
            
            
    // Build Infor Panel and display Image and Text.
            
    InforPanel = new JPanel();
            
    InforPanel.setLayout (new BorderLayout());
            
    centerPanel.add(InforPanel);
            
    // Build components for Infor Panel
            
    welcome = new JLabel ("Welcome to Java Flickr Application"JLabel.CENTER);
            
    InforPanel.add(welcomeBorderLayout.NORTH );
            
    lWelcome = new JLabel (iWelcome);   
            
    InforPanel.add(lWelcome);
            
            
    //Build recent Photo Panel to display most recent photos
            //recentPhotoPanel = new JPanel();
            //recentPhotoPanel.setLayout (new BorderLayout());
            //recentPhotoPanel.setVisible(false);
            //recentPhotoTitle = new JLabel ("Most Recent Photos on Flickr");
            //recentPhotoPanel.add(recentPhotoTitle);
            //centerPanel.add(recentPhotoPanel);
            
            //Build Search Panel to display area where user can search photos with a keyword
            
    searchPhotoPanel = new JPanel ();
            
    searchPhotoPanel.setLayout (new BorderLayout());
            
    searchPhotoPanel.setVisible(false);
            
    searchTitle = new JLabel ("Welcome to Search Area"JLabel.CENTER);
            
    searchPhotoPanel.add(searchTitleBorderLayout.NORTH);
            
    centerPanel.add(searchPhotoPanel);
            
            
    //Build all buttons with images
            
    btAfrica = new JButton(africa);
            
    btAsia = new JButton(asia);
            
    btAmerica = new JButton(america);
            
    btEu = new JButton(eu);
            
    btAus = new JButton(aus); 
            
            
    //Build Photo Pane to contain button and photo panel
            
    JPanel photoPane = new JPanel();
            
    photoPane.setLayout (new BorderLayout());
            
    //Build Button Pane to contain all image button
            
    JPanel buttonPane = new JPanel();
            
    buttonPane.setLayout( new FlowLayout());
            
    buttonPane.add(btAfrica);
            
    buttonPane.add(btAsia);
            
    buttonPane.add(btAmerica);
            
    buttonPane.add(btEu);
            
    buttonPane.add(btAus);
            
    photoPane.add(buttonPane,BorderLayout.NORTH );
            
    searchPhotoPanel.add(photoPaneBorderLayout.SOUTH);
    /**
     * @author Athina Ioannou 
     * @author Edited by Hung
     * @param code below to build all components that should be in Search Panel
     * @param adding all components and display them in Search Panel
     * @param Handling events when user clicks on button Search 
     * @param JTextField txtSearch
     */
            // Build Components for Search Content Panel
            
    sContent = new JPanel(); // content Panel to display conents
            
    sContent.setLayout( new FlowLayout()); 
            
    lblSearch =  new JLabel("Search");
            
    txtSearch = new JTextField(20);
            
    btnStart = new JButton("Start");
            
    btnExit = new JButton("Exit");
            
    //Add components to Search Panel and action handling    
            
    sContent.add(lblSearch);
            
    sContent.add(txtSearch);
            
    sContent.add(btnStart);
            
    btnStart.addActionListener(this);
            
    sContent.add(btnExit);
            
    btnExit.addActionListener(this);
            
    searchPhotoPanel.add(sContentBorderLayout.CENTER);
            
    // Build photo panel, photofinder and strings
            
    pp = new PhotoPanel();
            
    pp.setLayout (new FlowLayout());
            
    photoPane.add(pp);
            
    photoPane.setSize(600,400);
            
    //searchPhotoPanel.add(photoPane, BorderLayout.SOUTH);
            
    pf = new PhotoFinder();
            
    photoList = new ArrayList<Photo>();
            
    originalKeyWord "";
            
    oldKeyWord "";
            
    //titles = new ArrayList<String>();
            
    timer = new Timer(1000this);
            
        }
        
        public  
    void displayUserInterface()
        {
            
    testUserInterface1 test = new testUserInterface1 ();
            
    test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
    test.setTitle("Java Flickr Application");
            
    test.setSize(800,600);
            
    test.setVisible(true);
        }
        
        public 
    void actionPerformed(ActionEvent e
        { 
            if (
    e.getSource() instanceof JMenuItem
            {
                
    JMenuItem source = (JMenuItem)(e.getSource());
                
    //If user selects "Short-cut Key Guide" sub-menu, a dialog will be shown
                
    if (source.equals(hGuide))
                {
                    
                            
    JOptionPane.showMessageDialogtestUserInterface1.this,
                            
    "Select appropriate menu option that you want from Java Flickr Application\n" +
                            
    "User should navigate to menu before submenu\n" +
                            
    "Alt + F => select File menu \n" +
                            
    "Alt + E => select Exit submenu \n" +
                            
    "Alt + M => select Menu menu \n" +
                            
    "Alt + C => select Check Recent Photos submenu \n" +
                            
    "Alt + S => select Search submenu \n" +
                            
    "Alt + H => select Help menu \n" +
                            
    "Alt + S => select Short-cut Key Guide submenu \n" +
                            
    "Alt + A => select About Us submenu \n" ,
                            
    "Help Contents"JOptionPane.PLAIN_MESSAGE);
                    
                }
                
    //If user selects "About Us" sub-menu, a dialog will be shown
                
    if (source.equals(hAuthor))
                {
                    
    JOptionPane.showMessageDialogtestUserInterface1.this,
                            
    "Java Flickr Application is created by Fairy Tail Group \n\n" +
                            
    "Hung Vu Pham\n\n" +
                            
    "Jennifer Naiaretti\n\n" +
                            
    "Panagiota Tzana\n\n" 
                            
    "Athina Ioannou",
                            
    "About Us"JOptionPane.PLAIN_MESSAGEiAbout);
                }
                
    //If user selects "Check Recent Photos" sub-menu, a panel to retrieve all photos from Flickr and display photos 
               //if (source.equals(mRecentPhoto))
                //{
                //    InforPanel.setVisible(false);
                //    searchPhotoPanel.setVisible(false);
                //    recentPhotoPanel.setVisible(true);
                //}
                //If user selects "Search Photos" sub-menu, a panel to help user search photos on Flickr with specific keyword
                //This panel also contains all photo after searching.
                
    if (source.equals(mSearch))
                {
                    
    InforPanel.setVisible(false);
                    
    //recentPhotoPanel.setVisible(false);
                    
    searchPhotoPanel.setVisible(true);   
                    
    searchPhotoPanel.setSize(500,500);                
                }
                
    //If "Exit" sub-menu is selected, a window closes.
                
    if (source.equals(fExit))
                {
                    
    dispose();
                    
    System.exit(0);
                }
            }
            if (
    e.getSource() == btnExit)
            {
                
    dispose();
                
    System.exit(0);
            }
            if (
    e.getSource() == btnStart)
            {
                if (
    timer.isRunning())
                {
                    
    timer.stop();
                }
                
    keyWord txtSearch.getText();
                
    originalKeyWord keyWord;
                
    oldKeyWord keyWord;
                
    timer.start();
            }
            else
            {
                if (
    keyWord != null)
                {
                   
    Random r = new Random();
                   
    photoList.clear();
                   
                    
    photoList pf.doQuery(keyWord);
                    
    int i r.nextInt(photoList.size());
                    
    pp.setImage(photoList.get(i).getSmallUrl());
                    
    keyWord photoList.get(i).getTitle();
                    
    Iterator it photoList.iterator();
                    while (
    keyWord.equals(""))
                    {
                        
    Photo p = (Photo)it.next();
                        
    keyWord p.getTitle();
                    }
                    
    //if (oldKeyWord.equals(keyWord))
                    //{
                       // keyWord = originalKeyWord;
                       // }
                    //oldKeyWord = keyWord;
                   
    keyWord originalKeyWord;
                  {
                     
    //int num = photoList.size();
                    //for (int k=1; k < num; k++)
                   //jLabel[m].setIcon(photoList[m]);
                   
    pp.repaint();
                  }
                  
    System.out.println(keyWord);
           
                }

            }
        }
       } 


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    How many other sites is this question posted on?
    Please post links for them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Do not worry, (^^)
    I just posted one in this 4rum only.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Can you make a small complete program that compiles, executes and shows the problem? There is no way to test the posted code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Do you mean the jar file after executing ? or whole source code of all classes in this application ?

    I am using BlueJ IDE to code.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Make a small program that compiles, executes and shows the problem. If the problem is in the GUI, nothing else needs to be in the testing program.
    Don't post a jar file or the code for the whole project.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    I run the program and it works fine, there is no error. so I think the problem should be from GUI.

    By the way, "Make a small program that compiles, executes and shows the problem" means I should code something like JUnit Testing ???? from this program (like Junit testing) , it trace and show me the hidden error ???

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    No, a small, testable program (http://sscce.org/) has nothing to do with JUnit testing. It's a way to show the problem without a lot of extra, useless code getting in the way.

    I run the program and it works fine
    If the program works fine, have you found and solved the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Thanks for a website as Short, Self Contained, Correct Example,

    However, error is not shown up although the whole photos are not displayed fully.

    I think of the way using JPANEL as container, this can lure me into the problem.

    I use many JPanel as layers, one contains the others,

    as I make a new interface class for only search, simple with one container , 2 JPanel such as photoPanel and searchPanel
    searchPanel contains textfield and search button
    photoPanel shows photos when searching.
    =>The whole photos are fully displayed.

    then I lost my way now. Mostly I used BorderLayout to set positions of each JPanel.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    If you can't make a SSCCE, there is no way I can test to find problems.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    thanks, I got help frorm my friend and the problem is resolved

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Please mark this thread as solved.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    By the way, Norm, could you tell me how I use the the SSCCE Text Based Compiler.

    I copy my code n paste on the editor, however the error pops up saying that:

    No Complier Found in aa/bx/x.java
    It asks Tool.jar to run, but I can find it in many folders from JRE 7 and J2RE.x.x.x

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    how I use the the SSCCE Text Based Compiler.
    I'v never heard of that. I use the javac command to compile java programs:
    D:\Java\jdk1.6.0_29\bin\javac.exe -Xlint TestCode11.java
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    From the link you provided, I found the similar link to JDK folder in my pc

    C:\Program Files\Java\jdk1.7.0_07\bin

    can you let me how get back to C:\ by command line

    Because the command line from pc appears like C:\Users\YY

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    Ask Google about using DOS commands in windows.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Dec 2012
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can not retrieve full photo on java application, is it wrong with the way using JPanel setLayout ?

    thanks I got it

Similar Threads

  1. Program photo editing
    By samison in forum Paid Java Projects
    Replies: 0
    Last Post: August 21st, 2012, 08:53 AM
  2. Finding the edges of object in photo
    By Picker in forum Algorithms & Recursion
    Replies: 1
    Last Post: April 20th, 2012, 11:32 PM
  3. Java SE 7 OCA Training Lab Full Version Launched
    By treacyjane in forum The Cafe
    Replies: 0
    Last Post: November 4th, 2011, 08:57 AM
  4. Is java a power full programming language? can java do this?
    By Jhovarie in forum Java Theory & Questions
    Replies: 5
    Last Post: March 2nd, 2011, 02:02 PM
  5. Replies: 0
    Last Post: December 3rd, 2009, 04:43 PM