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 populate a jPanel?

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to populate a jPanel?

    Hello the Community,

    I try to display the result of a resultset in a JPanel but it does work.
    In a textArea it works. But the problem is you can write in it.

    Thank you for your advice.


    Habiler

    [CODE]
    private void intEmployeeNbrFocusLost(java.awt.event.FocusEvent evt) {
    searchPerson();
    // TODO add your handling code here:
    System.out.println("TextArea -1:" + EmployeeNbr);
    try {
    Class.forName("net.ucanaccess.jdbc.UcanaccessDrive r");
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(Ecran.class.getName()).log(Level. SEVERE, null, ex);
    }

    try {
    // establishing connection
    conn = DriverManager.getConnection("jdbc:ucanaccess://c:/Users\\hab\\Desktop\\Decisions1.accdb","","");
    } catch (SQLException ex) {
    Logger.getLogger(Ecran.class.getName()).log(Level. SEVERE, null, ex);
    }
    //JLabel lblFname, lblLname, lblPhoneNumber;

    PreparedStatement ps;
    int EmployeeNbr = Integer.parseInt(intEmployeeNbr.getText());
    try {
    System.out.println("TextArea 1:" + EmployeeNbr);
    String SQL = "SELECT * FROM Decisions where EmployeeNbr = ?";
    ps = conn.prepareStatement(SQL);
    ps.setInt(1 , EmployeeNbr);
    ResultSet rs2 = ps.executeQuery();

    System.out.println("TextArea 2:" + EmployeeNbr);

    while ( rs2.next()) {
    // String newValue = Double.toString(Math.floor(EmployeeNbr));
    int newDecNumber = (int)Math.floor(DecNumber);
    int newEmployeeNbr = (int)Math.floor(EmployeeNbr);
    int newPourcent = (int)Math.floor(Pourcent);

    long nelleValEmployeeNbr = new Double(newEmployeeNbr).longValue();
    long nelleValDecNumber = new Double(newDecNumber).longValue();
    long nelleValPourcent = new Double(newPourcent).longValue();

    System.out.println("NewValue:" + nelleValEmployeeNbr);
    String ListeSQL = (rs2.getString(1) + " " +nelleValEmployeeNbr + " " + nelleValDecNumber+ " "+ nelleValPourcent+"\n");
    jTextArea1.append(ListeSQL);
    jTextArea1.append(rs2.getString(1));

    System.out.println("panel:" + ListeSQL);
    }

    ps.close();
    }catch(SQLException e){

    JOptionPane.showMessageDialog(null, e);
    }

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: How to populate a jPanel?

    There are only two things you can add or do in a JPanel (aside from event handlers). One is to add other components such as JTextAreas, JTextFields, JComboBoxes, JButtons, etc. The other thing you can do is paint by overriding paintComponent(). If you want to write text into a JPanel the best thing to do is to add a specialized Component that lets you do that.

    Regards,
    Jim

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to populate a jPanel?

    Thanks Jim

Similar Threads

  1. Populate an array?
    By javaman1 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 20th, 2014, 05:37 PM
  2. JPanel within JPanel causing odd stretching behavior.
    By mstabosz in forum AWT / Java Swing
    Replies: 7
    Last Post: September 2nd, 2013, 06:32 AM
  3. Why I populate 2 times the same jTable
    By tomrey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 20th, 2013, 01:28 PM
  4. [SOLVED] Pesky <JPanel>.getWidth() and <JPanel>.getHeight() Methods...
    By snowguy13 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 31st, 2011, 03:35 PM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM