Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

positioning JLabels and Buttons in a JFrame

calculator jframe

  • Please log in to reply
7 replies to this topic

#1 Cruel Hand

Cruel Hand

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 195 posts
  • Programming Language:Java, Objective-C, Visual Basic .NET
  • Learning:C, Java, C++, Objective-C, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Pascal, Assembly, Haskell

Posted 30 March 2012 - 04:47 PM

I'm making a calculator and I have all the buttons and labels working correctly, I just need help positioning them. Like for example, how could I make a certain label appear on the bottom right hand corner of the screen, or make labels appear line after line after line to show different forms of calculations?

Thank you :)
  • 0

#2 Norm

Norm

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 397 posts
  • Location:Eastern Florida
  • Programming Language:Java, C++, Assembly

Posted 30 March 2012 - 04:59 PM

One way is to remove the layout manager and position everything yourself. You'll want to prevent resizing.
  • 0

#3 Cruel Hand

Cruel Hand

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 195 posts
  • Programming Language:Java, Objective-C, Visual Basic .NET
  • Learning:C, Java, C++, Objective-C, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Pascal, Assembly, Haskell

Posted 30 March 2012 - 05:10 PM

how do I remove the layout manager? Do you mean not use borderlayout?
  • 0

#4 Norm

Norm

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 397 posts
  • Location:Eastern Florida
  • Programming Language:Java, C++, Assembly

Posted 30 March 2012 - 05:12 PM

how do I remove the layout manager?

Set it to null.

Yes. If you remove it you will not be using it.
  • 0

#5 Cruel Hand

Cruel Hand

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 195 posts
  • Programming Language:Java, Objective-C, Visual Basic .NET
  • Learning:C, Java, C++, Objective-C, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Pascal, Assembly, Haskell

Posted 30 March 2012 - 05:17 PM

I'm already not using borderlayout though, so how can I specify where to put all the labels and buttons?
  • 0

#6 Norm

Norm

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 397 posts
  • Location:Eastern Florida
  • Programming Language:Java, C++, Assembly

Posted 30 March 2012 - 05:20 PM

Look at the API doc for the Component class. It has lots of methods for setting the size and locations and bounds of components.
  • 0

#7 Cruel Hand

Cruel Hand

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 195 posts
  • Programming Language:Java, Objective-C, Visual Basic .NET
  • Learning:C, Java, C++, Objective-C, PHP, (Visual) Basic, Python, JavaScript, Perl, Ruby, PL/SQL, Pascal, Assembly, Haskell

Posted 30 March 2012 - 06:26 PM

thanks man
  • 0

#8 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 31 March 2012 - 10:58 AM

I strongly suggest you always let a layout manager position your components for you.

I recommend GroupLayout. It's one of the most powerful and most flexible layout managers, while remaining fairly easy to use. I've converted all my classes over to it. It would be perfect for your calculator class.

How to Use GroupLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download