Results 1 to 5 of 5

Thread: JFrame add

  1. #1
    hayalimdesin is offline Member
    Join Date
    Oct 2015
    Posts
    7
    Rep Power
    0

    Default JFrame add

    hi friedns.

    active jframe form. I want to add one JLabel to the JFrame.

    with the code, How can I do.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JFrame add

    Have you tried anything?
    Looked at the API for JFrame to see what options there are?
    Gone through the Swing tutorial (not the Netbeans part) to see how all this fits together?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    hayalimdesin is offline Member
    Join Date
    Oct 2015
    Posts
    7
    Rep Power
    0

    Default Re: JFrame add

    I'm trying to do.

    import javax.swing.JLabel;

    public class Form extends javax.swing.JFrame {

    public Form() {
    initComponents();
    }

    @SuppressWarnings("unchecked")
    //Generated Code

    public static void main(String args[]) {
    Form f=new Form();
    JLabel lbl=new JLabel("hello");
    f.add(lbl);//add it to the active form


    //Look and feel setting code (optinal)


    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Form().setVisible(true);
    }
    });
    }

    // Variables declaration - do not modify
    // End of variables declaration
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: JFrame add

    Don't extend JFrame.
    There is almost never any need to do that.

    Does the above code work?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,991
    Rep Power
    8

    Default Re: JFrame add

    You are instantiating a new Form in the invokeLater method and NOT using your previously created one. Instead, use the Form you created:
    Java Code:
    public void run() {
      f.setVisible(true);
    }
    And what Tolls says +1
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Click in JFrame Titlebar sets the JFrame Opaque
    By tim8w in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2013, 07:29 AM
  2. Transferring information from one JFrame to Another JFrame
    By cherylminor85 in forum AWT / Swing
    Replies: 4
    Last Post: 05-24-2012, 05:24 AM
  3. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  4. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •