user interface - Java Increase Rectangle Thickness -
how increase thickness of rectangle when using g.drawrect
? want blue rectangle have thick line.
this code -
if(selectedapartment == 0) { g.setcolor(color.red); g.fillrect (150, 120,aptwidth, aptheight); **g.setcolor(color.blue); g.drawrect(150, 120, aptwidth, aptheight);** g.setcolor(color.black); g.setfont(new font("boldfont",font.bold,14)); g.drawstring("1", 150+15, 120+25); } else if (selectedapartment != 0) { g.setcolor(color.red); g.fillrect (150, 120,aptwidth, aptheight); g.setcolor(color.black); g.drawrect(150, 120, aptwidth, aptheight); g.setcolor(color.black); g.setfont(new font("boldfont",font.bold,14)); g.drawstring("1", 150+15, 120+25); }
you should use setstroke set stroke of graphics2d object.
here's example of code segment in program:
import java.awt.*; import java.awt.geom.line2d; import javax.swing.*; public class frametest { public static void main(string[] args) { jframe jf = new jframe("demo"); container cp = jf.getcontentpane(); cp.add(new jcomponent() { public void paintcomponent(graphics g) { graphics2d g2 = (graphics2d) g; g2.setstroke(new basicstroke(10)); g2.draw(new line2d.float(30, 20, 80, 90)); } }); jf.setsize(300, 200); jf.setvisible(true); } }
(note setstroke method not available in graphics object. have cast graphics2d object.)
Comments
Post a Comment