aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes what layouts to use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "what layouts to use" Watch "what layouts to use" New topic
Author

what layouts to use

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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?


SCJP
Visit my download page
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 21, 2000
Posts: 4347
    
    2

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

Joined: Oct 21, 2000
Posts: 4347
    
    2

i post my code so far here if anyone is interested:
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 21, 2000
Posts: 4347
    
    2

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what layouts to use