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

Thread: How to access combobox from another class in netbeans

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

    Default How to access combobox from another class in netbeans

    Hey guys,I make a coding a subject system for my internship project, I use JComboBox to choose name of faculty. I want to call selected item of faculty from another class to choose subject under the selected faculty.

    How can I call selected item from another class? Please help me.. thanks.
    This is my coding for select faculty.
    public class lectInterface(){
    private void saveDataActionPerformed(java.awt.event.ActionEvent evt) {

    String staff_id=staffID.getText();
    int staff_Id=Integer.parseInt(staff_id);
    String Name=staffName.getText();
    String Cpost=currPos.getText();
    String DPost=durrPos.getText();
    Object prog=textProgram.getSelectedItem();
    String hrs=hoursExcept.getText();
    int hours=Integer.parseInt(hrs);
    }



    and below is coding for another class

    try{
    LectInterface lI = new LectInterface();

    String host = "jdbc:derby://localhost:1527/STUDLECDB";
    String uName = "studlecdb";
    String uPass = "studlecdb";
    Connection con = DriverManager.getConnection( host, uName, uPass );

    stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSIT IVE, ResultSet.CONCUR_UPDATABLE);

    Object unit=lI.textProgram.getSelectedItem();
    if(lI.textProgram.getSelectedItem().equals("CS230 - BACHELOR OF COMPUTER SCIENCE(HONS)(SESSION 1 2015/2016)")){

    String sql = "SELECT SubjectName FROM Subject WHERE Program = 'CS230(1)'";
    rs = stmt.executeQuery(sql);
    while (rs.next()){
    String subj = rs.getString("SubjectName");

    SubjectList.addItem(subj);}
    }

    }
    catch(SQLException err){
    JOptionPane.showMessageDialog(LectInterface2.this, err.getMessage());

    }
    }


  2. #2
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: How to access combobox from another class in netbeans

    Make your JComboBox a class member variable and
    add a method to return the result.

    Btw - please use code tags when posting code. Thank you

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to access combobox from another class in netbeans

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly per the above link.

Similar Threads

  1. using netbeans gui to insert into ms access
    By Charles Nlegwu in forum Member Introductions
    Replies: 0
    Last Post: July 18th, 2013, 11:56 AM
  2. Replies: 0
    Last Post: April 14th, 2012, 11:22 AM
  3. Replies: 1
    Last Post: October 31st, 2011, 12:22 PM
  4. Netbeans and inner classes/variable access
    By jmorr212 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 17th, 2010, 10:22 PM
  5. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM