Results 1 to 13 of 13
  1. #1
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Question Help with java GUI

    Java Code:
    class CCIFrame extends JFrame{
            public CCIFrame(){
                
                super("Customer Check In");
                frameSetting(800,300,true);
    
                JPanel p1 = new JPanel();
                p1.setLayout(new FlowLayout(FlowLayout.CENTER,40,30));
                
                for(int i=1; i<=9; i++){
                    p1.add(new JButton("" +i));
                }       
                
                JPanel p2 = new JPanel();
                p2.setLayout(new BorderLayout());
                
                p2.add(p1, BorderLayout.CENTER);
                p2.add(new JTextField("Demo"), BorderLayout.NORTH);
                
                //Add contents to frame
                add(p2);
                
            }
    Why after i adding :
    p2.add(new JTextField("Demo"), BorderLayout.NORTH);
    It will display blank frame. I can't figure out what's going on

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Help with java GUI

    What is that: frameSetting(800,300,true); ?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    Java Code:
            private void frameSetting(int w, int h, boolean visibility){
                setSize(w,h);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setLocationRelativeTo(null);
                setVisible(visibility);
            }
    I write it to other method for re-usability.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Help with java GUI

    There you go, move the call to frameSetting into the last line of the constructor. You have to add the components before you show the window.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    It's working now. Thanks :)
    By the way, there was a weird problem happened. Sometime my compiler display nothing but after i maximize and restore back to windows size, all the content that i added to frame will come back. I'm using netBeans IDE 7.3.1

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Help with java GUI

    How do you start the window? Are you doing it on the EDT?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    Quote Originally Posted by PhHein View Post
    How do you start the window? Are you doing it on the EDT?
    What is EDT? Sorry for my stupidity

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Help with java GUI

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default Re: Help with java GUI

    Quote Originally Posted by CruelSoulz View Post
    What is EDT? Sorry for my stupidity
    Google: java swing edt

    5 seconds of effort. How long did it take you to post the question and wait for an answer? (which is the first hit of the google search). I'm not trying to be a prick, I'm just trying to illustrate to you how easy it is to find information. Try it yourself, you'll like it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    Quote Originally Posted by gimbal2 View Post
    Google: java swing edt

    5 seconds of effort. How long did it take you to post the question and wait for an answer? (which is the first hit of the google search). I'm not trying to be a prick, I'm just trying to illustrate to you how easy it is to find information. Try it yourself, you'll like it.
    The first time i google for EDT i didn't add "java" behind, that's why i can't found the result because i thought that EDT is something inside the OS haha

  11. #11
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    Thanks ... but still not quite understand about it, give me some time to digest it

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default Re: Help with java GUI

    Quote Originally Posted by CruelSoulz View Post
    The first time i google for EDT i didn't add "java" behind, that's why i can't found the result because i thought that EDT is something inside the OS haha
    That's a very useful discovery you just made then; when you google for something, put it into context for google so it can give more refined results. So if you want to search something relating to Java, put "java" in the search query.

    I always think back to what my dad did when he wanted to buy a barbeque. He put "barbeque" into Google (he still got some points for actually doing a search). That's great, if you want to read through endless blog posts about family barbeque adventures, but what he wanted to know was where to purchase a barbeque. When you know how to use Google properly, it is your best friend.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Help with java GUI

    Quote Originally Posted by gimbal2 View Post
    That's a very useful discovery you just made then; when you google for something, put it into context for google so it can give more refined results. So if you want to search something relating to Java, put "java" in the search query.

    I always think back to what my dad did when he wanted to buy a barbeque. He put "barbeque" into Google (he still got some points for actually doing a search). That's great, if you want to read through endless blog posts about family barbeque adventures, but what he wanted to know was where to purchase a barbeque. When you know how to use Google properly, it is your best friend.
    I agree with you.

Posting Permissions

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