Results 1 to 3 of 3
  1. #1
    nvnjolly is offline Member
    Join Date
    Oct 2015
    Posts
    1
    Rep Power
    0

    Post JTextfield not showing when run

    hey guys so everytime i run the code JTextfield doesnt show up (not visible)

    When i mouse over it it becomes visible.

    im kinda new to java. so can u tell me what im doing wrong?

    thanks.

    Java Code:
    package assignment;
    02
     
    03
    import java.awt.BorderLayout;
    04
    import java.awt.Color;
    05
    import java.awt.EventQueue;
    06
    import java.awt.Font;
    07
     
    08
    import javax.swing.JButton;
    09
    import javax.swing.JFrame;
    10
    import javax.swing.JLabel;
    11
    import javax.swing.JPanel;
    12
    import javax.swing.JTextField;
    13
     
    14
    public class Sample {
    15
         
    16
        private JFrame frame;
    17
        private JPanel panel;
    18
        private JLabel labelLogo;
    19
        private JLabel labelUser;
    20
        private JLabel labelPass;
    21
        private JButton button;
    22
        private JTextField textField1;
    23
        private JTextField textField2;
    24
         
    25
        public Sample() {
    26
             
    27
            gui();
    28
        }
    29
         
    30
        public void gui(){
    31
             
    32
            frame = new JFrame("HUMAN RESORUCE MANAGEMENT SYSTEM");
    33
            frame.setVisible(true);
    34
            frame.setSize(800,600);
    35
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    36
             
    37
            panel = new JPanel();
    38
            frame.getContentPane().add(panel, BorderLayout.CENTER);
    39
            panel.setLayout(null);
    40
            frame.add(panel);
    41
             
    42
            labelLogo = new JLabel("LOGIN");
    43
            labelLogo.setFont(new Font("Sitka Display", Font.BOLD | Font.ITALIC, 40));
    44
            labelLogo.setBounds(349, 116, 113, 51);
    45
            panel.add(labelLogo);
    46
             
    47
            labelUser = new JLabel("User Name");
    48
            labelUser.setFont(new Font("Tahoma", Font.PLAIN, 18));
    49
            labelUser.setBounds(219, 188, 86, 22);
    50
            panel.add(labelUser);
    51
             
    52
            labelPass = new JLabel("Password");
    53
            labelPass.setFont(new Font("Tahoma", Font.PLAIN, 18));
    54
            labelPass.setBounds(219, 232, 84, 25);
    55
            panel.add(labelPass);  
    56
             
    57
            textField1 = new JTextField();
    58
            textField1.setBounds(319, 188, 177, 29);
    59
            textField1.setColumns(10);
    60
            panel.add(textField1);
    61
             
    62
            textField2 = new JTextField();
    63
            textField2.setBounds(319, 228, 177, 29);
    64
            textField2.setColumns(10);
    65
            panel.add(textField2);
    66
             
    67
             
    68
             
    69
             
    70
             
    71
        }
    72
         
    73
        public static void main(String[] args){
    74
            new Sample();
    75
             
    76
        }
    77
         
    78
     
    79
         
    80
         
    81
         
    82
         
    83
         
    84
     
    85
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: JTextfield not showing when run

    Do you want us to guess what you did wrong? Describe the symptoms you don't like/want and we can help you. btw, I moved your post from the advanced section to this section and also btw, why did you manually add some sort of line numbers to your code?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: JTextfield not showing when run

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 07-17-2014, 02:27 PM
  2. Replies: 3
    Last Post: 11-14-2011, 05:13 AM
  3. JTextField not showing properly in GridBagLayout
    By aserothbw in forum AWT / Swing
    Replies: 13
    Last Post: 10-02-2009, 11:11 AM
  4. Replies: 1
    Last Post: 01-30-2009, 06:44 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
  •