Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Title/Icon bar thickness on Frame

Posted on 2004-03-31
8
Medium Priority
?
370 Views
Last Modified: 2008-03-04
I have an app that positions a component (JButton say) and draws a Rectangle2D around it.
This using Swing and Java2D with absolute positioning:
button.setBounds(80,60,45,30);
...
rect = new Rectangle2D.Double(75,75,60,45);

Okay, works fine until I run the app on my laptop and the button and rectangle don't line up.

It seems that I use Large Fonts for my Win98se under Properties/Settings and Small Fonts for my laptop. Yes, has the same (not wanted) result if I change the settings to Small.

I believe that Swing positions 0,0 from the working area of the frame (for me a gray color) and Java2D starts at the top corner of the frame (above the blue icon/title bar). For Large Fonts that bar is thicker and so the button moves down.

What I need is a Swing version like JRectangle ( and JLine for that matter).

Anything like this exist or is there another fix?

Thank you, Squeeto
0
Comment
Question by:Squeeto
  • 4
  • 2
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10728324
don't use absolute positioning.
instead use setBorder() to paint your rectangle.
0
 
LVL 92

Expert Comment

by:objects
ID: 10728338
or do your paining on the frames content pane.
0
 
LVL 1

Expert Comment

by:kiwi_alien
ID: 10728405
Don't set the size of the button - that really is just asking for trouble (Java is multi-platform and I'm sure you'd see weird stuff on a Mac, etc..)

Just let your button be sized by swing (with whatever constraints you would like)

Then draw your rectangle based on what the button thinks is its size is.  Just use myButton.getBounds() and render your Rectangle2D appropriately...  

If you want to know how big the title bar is and fudge appropriately then grab the content pane of the Frame and check its location.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Squeeto
ID: 10729320
Objects,
For this application, I would prefer to stay with absolute location and size.

I never had this problem when I used Buttons, Labels only JButtons, JLabels etc.

Kiwi Alien,
>grab the content pane of the Frame and check its location
Can you give me a specific line of code?
S.
0
 
LVL 1

Accepted Solution

by:
kiwi_alien earned 1000 total points
ID: 10729406
Ok if I create my JFrame with size 200,200.

JFrame frame = new JFrame(200,200);

and see how big my contentPane is...

Rectangle rect = frame.getBounds();

And print it out I get something like...

java.awt.Rectangle[x=0,y=0,width=192,height=173]

So what happened to my 200,200?  I lost 4 pixels each side and from the bottom so looks like I lost 23 pixels with the title bar etc.

Mileage will vary depending on Font used in Titlebar obviously.  I figure from that you can fudge a little and bang your box in the right place every time.

Course I still agree with objects and figure using a border is a better solution...  (-;
0
 
LVL 1

Expert Comment

by:kiwi_alien
ID: 10729411
That was a symptom of not enough proof-reading - should have been...

Rectangle rect = frame.getContentPane().getBounds();

Yep - it does work...
0
 

Author Comment

by:Squeeto
ID: 10729683
Kiwi Alien,
Yep - it does work...
For your 200x200 example, I got a height of 170 for Large Fonts and 175 for Small.  It is easy to adjust the positioning now.

BTW, I've had this question posted at Sun's Forum for 3 days now with maximum Duke dollars and have yet to get a response.  Good work and thanks.

Squeeto
0
 
LVL 1

Expert Comment

by:kiwi_alien
ID: 10729692
Happy to oblige...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question