• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what layouts to use

 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i finally came up with a small project to keep me busy for a while. i am writing a "copy" of windows Calculator program(in the standard view). if you have windows and could give your ideas on how to lay it out so it looks the same it would help some. so far, ignoring the menubar, i have a border layout with the TextField taking up north, and a panel with a grid layout taking center. however, this wont work because the top row has less components than the rest of the rows.

maybe if i give the panel a border layout, add a panel to it in north with a flow layout, and a panel to it in center with a grid layout?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
going by the calculator in vista:

panel1 - GridLayout(1,3,5,5) for the Backspace/CE/C buttons
panel2 - GridLayout(4,5,5,5) for the numeric/operater buttons
panel3 - BorderLayout - panel1 in NORTH, panel2 in CENTER
panel4 - GridLayout(5,1,5,5) for the Memory buttons and the blank button(?)
panel5 - BorderLayout - panel4 in WEST, panel3 in CENTER
panel6 - BorderLayout - JTextfield in NORTH, panel5 in CENTER
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. i will give that a try. i was already thinking i needed a separate panel for the memory buttons. the "blank button" is actually an uneditable textField (or JLabel)

that is close enough. i had to make my frame width greater than the windows version(or change font size i guess), but it looks quite similar otherwise
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i post my code so far here if anyone is interested:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's your same code a bit shorter, with a JLabel/loweredBevelBorder instead of uneditable JTextField
I had one too many panels in my first post - the one adding the textfield, which can be added directly to the frame
(will need size tweaking when menuBar added)

 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Michael, i figured out the extra panel was just the contentPane. your code is much shorter. i knew there had to be a way to loop through some of that stuff. i will look it over more closely later. i am bound to learn from it. now that i have it looking like a calculator i am finding that making it act like one is much harder. even if i dont finish it i will learn from it though. besides it is the first project idea i have had in a while. thanks again for helping me get started on it.

just compiled and ran your code. i see you managed to make it the same size as the microsoft version. now i for sure will have to read it to find out how.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic