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 4 of 4

Thread: Calling Public Function in JInnternalFrame

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Calling Public Function in JInnternalFrame

    This may be a total newb question, but Is it possible to create a JInternalFrame class with additional public functions that can be called from the desktop?

    Here is some snippets of the code.

    This is the Internal Frame with the public functions added after the constructor.

    public class Search_Ifr extends javax.swing.JInternalFrame {
     
        /**
         * Creates new form Search_Ifr
         */
        public Search_Ifr() {
            initComponents();
        }
     
        public void setTabPaneIndex(int tabIndex){
            this.tpnSearch.setSelectedIndex(tabIndex);
        }
        public void setTabPaneIndex(String tabName){
            for (int i=0; i < this.tpnSearch.getTabCount(); i++){
                if(tabName.equals(this.tpnSearch.getTitleAt(i))){
                    this.tpnSearch.setSelectedIndex(i);
                    break;
                }
            }
        }
    }

    This is where I am calling the function from the desktop.
    private void findCustomerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                                     
            // TODO add your handling code here:
            JInternalFrame ifrSearch = new Search_Ifr();
            ifrSearch.setVisible(true);  //rootPaneCheckingEnabled
            ifrSearch.setTabPaneIndex("tabCust");
            this.desktopPane.add(ifrSearch);
            try {
                ifrSearch.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
        }

    The line " ifrSearch.setTabPaneIndex("tabCust");" is throwing a compile error that the method is not found.

    Any help would be greatly appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,401
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Calling Public Function in JInnternalFrame

    If the setTabPaneIndex method is defined in your class, you need to use a reference to an instance of your class to call it. It is not part of the JInternalFrame class.
    Define ifrSearch as a reference to your class or cast it to be a reference to your class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Calling Public Function in JInnternalFrame

    Thank you for the quick response Norm, but am I not using a reference to my class by defining it as a variable first and then using that varable to call the method?
    or should I change this line "JInternalFrame ifrSearch = new Search_Ifr();" to "Search_Ifr ifrSearch = new Search_Ifr();".

    --- Update ---

    Problem solved. That is totally what the problem was. Thank you Norm. As I said a total numb question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,401
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Calling Public Function in JInnternalFrame

    Glad you solved it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. public file name
    By vidhika rajani in forum Java Theory & Questions
    Replies: 1
    Last Post: October 28th, 2013, 09:18 PM
  2. Calling A Public Static Void Method from Main
    By Clubs in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 27th, 2013, 02:29 AM
  3. What is Wrong When calling the function using arrayList.
    By nutan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 26th, 2013, 07:30 AM
  4. Java, calling another public class from within the main class giving problems.
    By RandomGaisha in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 26th, 2012, 01:30 PM
  5. Public class help/error
    By Plural in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 11th, 2010, 05:22 PM