Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to set line width using Graphics.drawRect?

Posted on 2000-04-06
4
Medium Priority
?
1,165 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 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