-1

The code written below only shows this is it in console why is it not showing the UI which i have made i have used windows builder to create the UI.

 import javax.swing.JFrame;

    public class getData extends JFrame {

         JFrame frame = new JFrame();
         JTextArea textArea = new JTextArea();
         JTextArea textArea_1 = new JTextArea();
         JTextArea textArea_2 = new JTextArea();
         JLabel    lblNewLabel = new JLabel("BOX");
         JLabel    lblPlc = new JLabel("PLC");
         JLabel    lblHmi = new JLabel("HMI");
         JButton   btnSubmit = new JButton("SUBMIT");
         JButton   btnExport = new JButton("EXPORT");


        public getData() {
            initGUI();
    }   
        void initGUI(){

            getContentPane().setLayout(null);
            this.textArea.setBounds(28, 50, 105, 162);

            getContentPane().add(this.textArea);
            this.textArea_1.setBounds(183, 50, 105, 162);

            getContentPane().add(this.textArea_1);
            this.textArea_2.setBounds(319, 50, 105, 162);

            getContentPane().add(this.textArea_2);
            this.lblNewLabel.setFont(new Font("Times New Roman", Font.PLAIN, 13));
            this.lblNewLabel.setBounds(28, 25, 46, 14);

            getContentPane().add(this.lblNewLabel);
            this.lblPlc.setFont(new Font("Times New Roman", Font.PLAIN, 13));
            this.lblPlc.setBounds(183, 25, 46, 14);

            getContentPane().add(this.lblPlc);
            this.lblHmi.setFont(new Font("Times New Roman", Font.PLAIN, 13));
            this.lblHmi.setBounds(317, 25, 46, 14);

            getContentPane().add(this.lblHmi);
            this.btnSubmit.setFont(new Font("Times New Roman", Font.PLAIN, 13));
            this.btnSubmit.setBounds(22, 228, 89, 23);

            getContentPane().add(this.btnSubmit);
            this.btnExport.setFont(new Font("Times New Roman", Font.PLAIN, 13));
            this.btnExport.setBounds(300, 228, 89, 23);
            getContentPane().add(this.btnExport);
            frame.setSize(500, 500);
            frame.add(getContentPane());        
            frame.setTitle("Bar Code Scanner");
            frame.setVisible(true);     
    }        
        public static void main(String[] args) {
            System.out.println("This Is It");       
        }   
    }

Also it displays when i switch the tab from source to design. Thanks in Advance.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Cent
  • 5
  • 1
  • 2
    class getData seriously? Follow naming conventions.... looks like you gave method name to a class. – Aniket Thakur Apr 25 '14 at 08:32
  • Would changing it solve the problem? It is kept because it fetches data from the barcode scanner. – Cent Apr 25 '14 at 08:35
  • I answered your problem below. Above was a suggestion. Also why are you creating new JFrame object inside your class when your class itself extends JFrame? – Aniket Thakur Apr 25 '14 at 08:38
  • Your answer does not solve the problem. let me know the direct changes if i have to display the frame when i run the program. – Cent Apr 25 '14 at 09:22
  • Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Apr 25 '14 at 09:54

3 Answers3

1

In intiGUI() method, replace frame with 'this'.

        frame.setSize(500, 500);
        frame.add(getContentPane());        
        frame.setTitle("Bar Code Scanner");
        frame.setVisible(true); 

Use the below code:

        this.setSize(500, 500);
        this.add(getContentPane());        
        this.setTitle("Bar Code Scanner");
        this.setVisible(true); 

Here current class itself is a JFrame and you have added the components to current content pane. hence you need to set size and visibility to the current JFrame i.e. current class.

public static void main(String[] args) 
{

  System.out.println("This Is It"); 

   new getData();     // ** You need to instantiate the class

}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Munesh
  • 1,509
  • 3
  • 20
  • 46
0

You need to actually make the JFrame object

    public static void main(String[] args) {
        System.out.println("This Is It"); 
        JFrame frame = new getData();     
    } 
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

You should replace the JFrame inside your class with itself.

  • Remove JFrame frame = new JFrame();
  • Replace frame.setSize(500, 500) with this.setSize(500, 500)
  • Repeat that with every other occurence of frame

Then you have to make the JFrame-Object.

public static void main(String[] args) {
  System.out.println("This Is It"); 
  getData yourFrame = new getData();     
} 
Alexander_Winter
  • 314
  • 1
  • 3
  • 9