?
Solved

How to set line width using Graphics.drawRect?

Posted on 2000-04-06
4
Medium Priority
?
1,100 Views
Last Modified: 2008-02-01
im using Graphics.drawRect to draw some rects. how can i adjust the line width ?

Thanks,
  P
0
Comment
Question by:pipe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:Daman
ID: 2692085
after
void drawRect(int top, int left, int width, int height)
call
fillRect(int top, int left, int width, int height

eg,
if you want to have rect(100*50) of width 5

call

c1.drawRect(10, 10, 100, 50)
c2.fillRect(10, 10, 100, 50)
c1.fillRect(15, 15, 90, 40)

(where c1 and c2 are "black" and "red" color)


This will work for you.
0
 
LVL 4

Expert Comment

by:jerch
ID: 2692133
Hi pipe...
Do you mean the thickness of the line? I don't think you can set it.  You can do this instead.

        int thickNess = 4;
        for (int i = 0; i < thickNess; i++)
            g.drawRect(x + i, y + i, width - 2 * i, height - 2 * i);

regards..
Jerson
0
 
LVL 2

Accepted Solution

by:
stalefish earned 400 total points
ID: 2692226
Actually, if you use Graphics2D, you can adjust the thickness

public void paint(Graphics g){
  BasicStroke stroke = new BasicStroke(5); //5 pixels wide
  Graphics2D g2 = (Graphics2D) g;
  g2.setStroke(stroke);
  g2.drawRect(w,x,y,z);
  ...
}
0
 

Expert Comment

by:aniket040700
ID: 2693073
the possible option is using drawRect() for straight lines only.

public void paint(Graphics g)
{
   g.drawRect(int a, int b, widht w, height h);
}

a and b are the co-ordinates

w is the length of the line

h is the thickness
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 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