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 5 of 5

Thread: How to write above a JPanel

  1. #1
    Junior Member bruno88's Avatar
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to write above a JPanel

    Hey guys!

    I'm working on a little game at the moment and I'm with a problem. I have a JPanel where the game runs and above it in one corner I want to write the total points of the player but I don't know how to do it. I tried a lot of things and nothing Can you help me please?


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: How to write above a JPanel

    What type of layout are you using? You should use a JLabel to display the score.

    Take a look at these different layout managers. Position your JLabel above the JPanel.

    How to Use Various Layout Managers (The Java™ Tutorials > Creating a GUI with JFC/Swing > Laying Out Components Within a Container)
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member bruno88's Avatar
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to write above a JPanel

    Well I'm using a GridBagLayout now and I'm writing the points on a JLabel and finally it wroked ^^ But I have something wrong on my code :s The text appears in center of JPanel instead of the FIRST_LINE_END. Can you please tell me what's wrong on my code?

    GridBagConstraints c = new GridBagConstraints();
     
    		label = new JLabel();
     
    		c.fill = GridBagConstraints.HORIZONTAL;
    		c.ipady = 40;	//Altura
    		c.anchor = GridBagConstraints.FIRST_LINE_END;	//Posição
    		c.gridx = 2;
    		c.gridwidth = 2;	//Número de colunas.
    		c.gridy = 0;	//Numero da linha.
    		add(label, c);

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: How to write above a JPanel

    Hello bruno88

    Can you please post all of your code for me to look at? I need to compile it to see the problem..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member bruno88's Avatar
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to write above a JPanel

    Hello,

    I decided to use the drawString method from Graphics2D and it did what I want. Anyway thank you very much for your help, that link about layout managers can be very helpfull in future ^^

Similar Threads

  1. How to Write a simple XMPP (Jabber) client using the Smack API
    By JavaPF in forum Java Networking Tutorials
    Replies: 35
    Last Post: August 5th, 2014, 12:59 AM
  2. Writing in a file using Java
    By JavaPF in forum File Input/Output Tutorials
    Replies: 4
    Last Post: December 17th, 2011, 04:33 PM
  3. Someone please help me write a simple program!!!
    By ocean123 in forum Loops & Control Statements
    Replies: 3
    Last Post: June 14th, 2009, 09:46 PM
  4. 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
  5. Replies: 4
    Last Post: May 27th, 2008, 01:20 PM