473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Frame Border

SammyB
807 Expert 512MB
I am creating a Frame with a checkerboard. Currently the checkerboard and the two other panels fill the entire form, but I would like to have a 20 pixel border of blank space around the three frames, but I can only change the spacing between frames. How do I do this?

My class extends Frame and the important constructor lines are below (I've left out the TextArea constructors & the panel.add's). I've attached a sketch of what I would like it to look like.
Expand|Select|Wrap|Line Numbers
  1. Panel pnlCheckerboard = new Panel();
  2. TextArea txtSquare[] = new TextArea[16];
  3. //
  4. Panel pnlInput = new Panel();
  5. TextField txtStart = new TextField(8);
  6. TextField txtStop = new TextField(8);
  7. TextField txtStep = new TextField(8);
  8. Label lblStart = new Label("Start");
  9. Label lblStop = new Label("Stop");
  10. Label lblStep = new Label("Skip");
  11. //
  12. Panel pnlButtons = new Panel();
  13. Button btnGo = new Button("Go");
  14. Button btnClear = new Button("Clear");
  15. //
  16. this.setLayout(new BorderLayout(10,10));
  17. pnlCheckerboard.setLayout(new GridLayout(4,4,10,10));
  18. pnlInput.setLayout(new GridLayout(2,3,10,10));
  19. pnlButtons.setLayout(new FlowLayout(FlowLayout.CENTER,50,1));
  20. // Bunches of add's left out
  21. this.add(pnlCheckerboard, NORTH);
  22. this.add(pnlInput, CENTER);
  23. this.add(pnlButtons, SOUTH);
  24.  
Attached Images
 
Oct 15 '07 #1
3 3228
JosAH
11,448 Expert 8TB
Add all those components to another JPanel. Have a look at the BorderFactory.
Make it create an EmptyBorder 20 pixels wide on all sides. Set that border
to the JPanel. Finally add that JPanel to your Frame and voila.

kind regards,

Jos

ps. Better use a JFrame (Swing) instead of a Frame (AWT)
Oct 16 '07 #2
SammyB
807 Expert 512MB
Add all those components to another JPanel. Have a look at the BorderFactory.
Make it create an EmptyBorder 20 pixels wide on all sides. Set that border
to the JPanel. Finally add that JPanel to your Frame and voila.

kind regards,

Jos

ps. Better use a JFrame (Swing) instead of a Frame (AWT)
Yep, that worked. Couldn't figured out how to use a JFrame (comes in later chapters), so I just shoved a JPanel into the Frame. It was not pretty, but I tweaked the TextField & TextArea sizes and the form size until it looked great. Thanks!
Oct 16 '07 #3
JosAH
11,448 Expert 8TB
Yep, that worked. Couldn't figured out how to use a JFrame (comes in later chapters), so I just shoved a JPanel into the Frame. It was not pretty, but I tweaked the TextField & TextArea sizes and the form size until it looked great. Thanks!
There's OGR (tm) (OGR == One Golden Rule) that says: never mix AWT and Swing
components; the two don't like each other. Instead of a JPanel and a Border
you could have a look at the Canvas and Insets classes; they can
do more or less the same and AWT understands them.

A bit of explanation: AWT uses the system available visual components for the
actual drawing, so e.g. an AWT Button has a 'ButtonPeer' that calls the native
windowing system to do the drawing. Such a component is called a 'heavy weight'
component. Swing takes the other route and does all the drawing itself, entirely
written in Java. (Swing was slow in the early days). Swing doesn't know about
those heavy weight components so if you place two or more of them near each
other or even on top of them two drawing systems are invoked and Swing doesn't
know that and AWT doesn't know that the native system doesn't draw certain parts
of the screen; the net result is a mess.

kind regards,

Jos
Oct 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul | last post by:
I have a simple frame-based application where title information appears in a top frame and a lower frame contains the content for the application. One of the needs for this app is for a status...
24
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two...
2
by: RWD | last post by:
I am trying to figure out how to change the target frame in my hyperlink on a DHTML menu. The menu is in one frame and the target frame is called "main" The code is below: Thanks in advance...
14
by: Frances Del Rio | last post by:
if (parent.frames.main.location == 'mediaselect.html') { I have a very simple frameset, name of frame where I'm checking is 'main'... why is this not working? I mean this is correct syntax,...
7
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
6
by: wimvan | last post by:
Hi, I'm a nerd in javascript, but, after trying and retrying I'm addressing me to help. I have a page with three frames, a top-, a left- and a right-frame. a kind a title-frmae, a button-frame...
0
by: hari24patil | last post by:
Hi , I am not geting frame border in firefox i want only right border of frame to be show and all other border are hidden it work in IE but in firefox it not show border and due to that i am not...
1
by: sayid | last post by:
Hello, I have a problem when altering a DIV-element from another frame. The frameset looks like this: <frameset rows=0,0,* border=0> <frame name=header src=/header.htm scrolling=no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.