Drawing thick line

Hi,
For some graphical user interface, I was overriding PaintComponent() method with Graphics argument and then using drawLine() method of Graphics class of Java. It worked in the way I wanted. However, the lines drawLine() method draws are too thin. For that purpose, I defined paintComponent() method with Graphics2D class to use its setStroke() method. I left all previously defined methods, namely drawRect() and fillOval() unchanged due to the fact that Graphics2D class extend Graphics class. However, now no input is displayed on myJFrame although I get no compile errors. Has anyone idea about the problem?
Thanks in advance,

public void paintComponent(Graphics2D g)
     for(int i=0; i<myBoard.size; i++)
          for(int j=0; j<myBoard.size; j++)
               g.setColor (Color.black);
               g.drawRect (50*j, 50*i, 50, 50);
               if(myBoard.board[i*2][j*2] == 1)
                    g.setColor (Color.black);
                    g.fillOval (50*j, 50*i, 50, 50);
               else if(myBoard.board[i*2][j*2] == 2)
                    g.setColor (Color.lightGray);
                    g.fillOval (50*j, 50*i, 50, 50);
     int width = 3;
     BasicStroke bs = new BasicStroke(width);
     g.setStroke(bs);
     g.setColor (Color.red);
     for(int i=0; i<myBoard.size*2-1; i++)
          for(int j=0; j<myBoard.size*2-1; j++)
               if(myBoard.board[i][j] == 3)
                    g.drawLine(j*25, (i+1)*25, (j+2)*25, (i+1)*25);
               else if(myBoard.board[i][j] == 4)
                    g.drawLine((j+1)*25, i*25, (j+1)*25, (i+2)*25);
public static void main(String args[])
       JFrame frame = new JFrame("Output");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.setLayout(new GridLayout());
     Main panel = new Main();
     frame.add(panel);
     frame.setSize(50*myBoard.size+8, 50*myBoard.size+33);
     frame.setVisible(true);
}I was hoping to see thick lines but there is displayed nothing on the frame, I don't know why (Why?). (It gives thin lines when I change argument of paintComponent from Graphics2D to Graphics and comment out 3 lines using setStroke().)

Similar Messages

  • How can you draw a thicker line!

    Hi,
    Do you know how to draw a thicker line without
    using Graphics2D? I can not use setStroke because
    if I use graphics2d class, the user have to download
    JRE to run my applet.
    Thanks

    Use the end-points of your line to create a Polygon which provides a border round it, then use Graphics.fillPolygon.

  • Drawing preloader line with AS?

    Hello
    I have the following AS (2) in a preloader (which works - in
    the sense that it loads the next page):
    The preloader should have a coloured line which runs from
    left to right about 0.25px thick.
    Whenever I have tried to draw the line using a pencil, it
    appears too thick, or uneven, or even goes from right to left.
    I have noticed that if I occasionally delete efforts I do not
    like, even the next page fails to load.
    What I am asking here is if it would be possible to draw the
    line in AS?
    Thanks for any useful advice.
    Steve

    Hello Devendran
    Many thanks for your post.
    So I would use something like:
    lineStyle( 1, 0xBDA0F2, 100 );
    moveTo( x1, y1 );
    lineTo( x2,y2 );
    But how would I incorporate that into my current Preloader AS
    (2)?
    Many thanks.
    Steve

  • Draw a line of certain length?

    Hi there...
    does someone know a mathematical algorithm to draw a line of a certain length using the drawLine - method??
    thx
    Jebediah

    lol, it has been rather easy :). I just had to think a few seconds about it.
    public boolean drawLine(int x, int y, int oldX, int oldY){
              // if we have a line and not a point
              int thickness = 4;
              if (!(oldX==x&&oldY==y)){
                   int vectorX = oldX - x;
                   int vectorY = oldY - y;
                   double vectorLength = waba.util.Math.sqrt(waba.util.Math.pow(vectorX, 2)+waba.util.Math.pow(vectorY, 2));
                   double desiredLength = 20;
                   double newVectorX = vectorX/vectorLength*desiredLength;
                   double newVectorY = vectorY/vectorLength*desiredLength;
                   g.drawLine(oldX, oldY, oldX - (int)newVectorX, oldY - (int)newVectorY);
    return true;

  • I can't draw straight lines for fill-in-the-blank on my tests and worksheets. The "draw it yourself choice makes big fat lines and takes a lot of manipulation. Do I have to draw them myself with a pen and a ruler?

    I can't draw straight lines for fill-in-the-blank on tests and worksheets. The draw-it-yourself ooption gives me thick lines and is time-consuming. So, after all these years, do I have to go back to using a ruler and a pen?

    In Pages v5.0.1, the straight lines are already drawn for you in the Shape Tool. Before we go there, select Menu > View > Show Ruler.
    When you click on Shape in the Pages toolbar, the top left line is straight. Click it. It will drop into your document in a 45 degree angle. Grab the lower left selection grip and drag it up and to the right to position the horizontal line in the length of your choice. Use the Format: Style tab to manage the stroke weight. You can also choose Menu > Edit > Duplicate Selection (command+D) as a productivity tool.
    If you move from the Format: Style tab to the Arrange tab, you can compare the start and end points with where you want the line positioned on the ruler. Once you have it positioned, notice the Lock button, also on the Format: Arrange tab.

  • How can I made a thicker line??

    Dear all,
    I want to draw a line on a panel. I have try drawLine() from Graphics and new a Line2D.Double and use Graphics2D to draw it.
    However, I can't draw a thicker line. So I want to ask if there is any method that I can draw a thicker line on the panel?
    Thx a lot.
    From
    samhome

    Dear jboeing,
    Yeah~~~~~~
    Thx for your reply. I can make a thicker line now.
    Really really thx. You have helped me a lot.
    From
    samhome

  • How to draw multiple lines on same panel??

    hiya
    i would like to know how can I draw multiple lines on the same panel ?? I have already use repaint(); but it just come out the lastest line (say line 3) i draw .......those previous lines(say line 1 and 2) are disappear ........
    Thanks for your help mate

    http://www.java2s.com/ExampleCode/2D-Graphics/Line.htm

  • How to draw horizontal line in smartform after end of the all line items

    Hi Friends,
    I am working on the smartform. I have created TABLE node in Main window.
    i want to draw a horizontal line after end of the main window table node. i mean after printing all the line items of the table, I need to print one horizontal line.
    Could you please help me how to resolve this issue.
    FYI: I tried with the below two options. But no use.
    1. desinged footer area in the table node of the main window.
    2. tried with uline and system symbols.
    please correct me if i am wrong. please explain in detail how to draw horizontal line after end of the main window table.
    this is very urgent.
    Thanks in advance
    Regards
    Raghu

    Hello Valter Oliveira,
    Thanks for your answer. But I need some more detail about blank line text. i.e thrid point.
    Could you please tell me how to insert blank line text.
    1 - in your table, create a line type with only one column, with the same width of the table
    2 - in table painter, create a line under the line type
    3 - insert a blank line text in the footer section with the line type you have created.

  • Can we draw multiple lines on a single CAShapeLayer?

    I want to draw multiple lines on a single layer of CAShapeLayer by UITouch. Is it possible?

    if they use the same appleID then you can do it at www.icloud.com

  • How to draw a line in smartforms!

    Hello ABAPers,
    In smartform, I am having a table. Every 3 rows I want to draw a line. How can I do that in Smartforms?
    Thanks,

    hi Naren,
    Check these links out
    drawing line in smartforms
    Re: Smartforms - Line Height
    Re: smartforms blank line
    Regards,
    Santosh

  • Here are my last 3 duke dollars.  Can someone please help me draw a line?

    I have been BEATING my head on this for well over a week now. I'm new to Java2D and I cannot find even one example of this simple little thing that I am trying to do. Not one.
    All I want to do is draw an image, zoom that image, then draw some lines on that image, and then zoom it and have those lines show up where they should.
    For example, we have an image which has been zoomed. No lines are yet drawn on it.
    A line is added.
    The image is then zoomed in or out one more time.
    How do we get the line to remap to the newly zoomed image?
    What I am doing is:
    0) Load up an image from a file.
    1) Create a zoomed image by using the Image.getScaledInstance() method.
    2) Create a BufferedImage with the width and height of the image AFTER the zoom has taken place.
    3) Create a Graphics2D object by the createGraphics from this BufferedImage.
    4) Place the image into the BufferedImage by doing a BufferedImage.drawImage
    5) Select two points to be the start and end of the line.
    6) Draw the line using Graphics2D.drawLine(start.x, start.y, end.x, end.y).
    7) Zoom the image again (using the Image.getScaledInstance() method.
    8) Create a new ImageIcon using the image from above and override its paintIcon method like this:
    ImageIcon newIcon = new ImageIcon(newImage) {                       
    public void paintIcon(Component c, Graphics g, int x, int y)
    super.paintIcon(c, g, x, y);
    zoom(); //<---- ZOOM call
    Now in the zoom routine, what do I need to do to get the lines to draw at the proper location and size?
    Remember, the points of the lines (stored in a list as home grown line objects) are in screen coordinates, not image coordinates since they are just click points
    Note that when I use these points to draw a line, all is well (the line gets drawn where it should), but I have problems when I zoom the image.
    Thanks!

    Below is the documentation and method signature of
    Graphics.drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer);The important thing to note is that it does scaling on the fly if the size dictated by the source co-ordinates is defferent than the size dictated by the destination co-ordinates. The source image is always left un-touched.
    So basically your visual data is located in an offscreen image. You can draw a line on that. Then create a new image, get it's graphics and call drawImage(original_image, co-ordinates that cause it to scale how you like).
    Then you can draw lines on the 2nd image, create a 3rd, ...etc
         * Draws as much of the specified area of the specified image as is
         * currently available, scaling it on the fly to fit inside the
         * specified area of the destination drawable surface. Transparent pixels
         * do not affect whatever pixels are already there.
         * <p>
         * This method returns immediately in all cases, even if the
         * image area to be drawn has not yet been scaled, dithered, and converted
         * for the current output device.
         * If the current output representation is not yet complete then
         * <code>drawImage</code> returns <code>false</code>. As more of
         * the image becomes available, the process that draws the image notifies
         * the specified image observer.
         * <p>
         * This method always uses the unscaled version of the image
         * to render the scaled rectangle and performs the required
         * scaling on the fly. It does not use a cached, scaled version
         * of the image for this operation. Scaling of the image from source
         * to destination is performed such that the first coordinate
         * of the source rectangle is mapped to the first coordinate of
         * the destination rectangle, and the second source coordinate is
         * mapped to the second destination coordinate. The subimage is
         * scaled and flipped as needed to preserve those mappings.
         * @param       img the specified image to be drawn
         * @param       dx1 the <i>x</i> coordinate of the first corner of the
         *                    destination rectangle.
         * @param       dy1 the <i>y</i> coordinate of the first corner of the
         *                    destination rectangle.
         * @param       dx2 the <i>x</i> coordinate of the second corner of the
         *                    destination rectangle.
         * @param       dy2 the <i>y</i> coordinate of the second corner of the
         *                    destination rectangle.
         * @param       sx1 the <i>x</i> coordinate of the first corner of the
         *                    source rectangle.
         * @param       sy1 the <i>y</i> coordinate of the first corner of the
         *                    source rectangle.
         * @param       sx2 the <i>x</i> coordinate of the second corner of the
         *                    source rectangle.
         * @param       sy2 the <i>y</i> coordinate of the second corner of the
         *                    source rectangle.
         * @param       observer object to be notified as more of the image is
         *                    scaled and converted.
         * @return   <code>true</code> if the current output representation
         *           is complete; <code>false</code> otherwise.
         * @see         java.awt.Image
         * @see         java.awt.image.ImageObserver
         * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
         * @since       JDK1.1
        public abstract boolean drawImage(Image img,
                              int dx1, int dy1, int dx2, int dy2,
                              int sx1, int sy1, int sx2, int sy2,
                              ImageObserver observer);

  • How to draw horizontal line at the end of table for multiple line items

    Dear Experts,
                       Pls can anyone help me how to draw horizontal line at the end of table for multiple line items . kindly help me regarding this
    Thanks
    Ramesh Manoharan

    Hi
       I tried as per your logic but it is not solving my problem .  when i am gone to table painter it is showing line type 1 and line type 2
      is below format.. if u see here line type 1 bottom line and line type 2 top line both are same..  so how to avoid this ?
                              line type 1
                             line type 2

  • Problem in drawing a line in Java Application Program

    Hi,
    I am trying to draw a line after a message is displayed on the screen. But the line is not at all coming on the screen while running. but I can see a red line is appearing on the screen first and and it is getting overridden.
    There is something wrong in the concept what I understood about graphics.Can anybody help to
    understand where the problem is ?
    Here is the part of the code which used to draw line.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.util.Date.*;
    import java.text.*;
    import java.lang.*;
    import MyPack.*;
    class chalan_pay extends JFrame
    JTextField jt1,jt2,jt3,jt4,jt5;
    JLabel jlh,jl1,jl2,jl3,jl4,jl5,jl10;
    JButton bt1,bt2,bt3;
    Choice ch1,ch2,ch3,ch4;
    Connection con = null;
    int i1no,i2no,i3no,i4no,itno;
    String idate;
    public chalan_pay()
    getContentPane().setLayout(null);
    jt1= new JTextField(5);
    jt1.setBounds(110,150,50,20);
    jt2= new JTextField(10);
    jt2.setBounds(400,150,100,20);
    jt3= new JTextField(3);
    jt3.setBounds(590,150,30,20);
    jt4= new JTextField(2);
    jt4.setBounds(750,150,30,20);
    jlh= new JLabel();
    jlh.setText("CHALLAN DETAILS");
    jlh.setBounds(300,50,200,20);
    jl1= new JLabel();
    jl1.setText("IGM No. ");
    jl1.setBounds(50,150,100,20);
    jl2= new JLabel();
    jl2.setText("IGM Date ");
    jl2.setBounds(340,150,100,20);
    jl3= new JLabel();
    jl3.setText("Line No. ");
    jl3.setBounds(530,150,100,20);
    jl4= new JLabel();
    jl4.setText("Subline No. ");
    jl4.setBounds(680,150,100,20);
    jl10= new JLabel();
    jl10.setBounds(100,200,300,20);
    ch1= new Choice();
    ch1.setBounds(170,150,150,20);
    getContentPane().add(ch1);
    ch1.addItemListener(new Opt1());
    bt1= new JButton("Exit");
    bt1.setBounds(200,600,100,20);
    getContentPane().add(bt1);
    bt1.addActionListener(new Ex());
    try
    con=db_connect.getConnection();
    Statement st1 = con.createStatement();
    ResultSet rs1 = st1.executeQuery("select igm_no,to_char(igm_dt,'DD-MON-YY'),line_no,subline_no from "+
    "det_item order by igm_no");
    while(rs1.next())
    ch1.addItem(String.valueOf(rs1.getInt(1))+" "+rs1.getString(2)+" "+
    String.valueOf(rs1.getInt(3))+" "+String.valueOf(rs1.getInt(4)));
    rs1.close();
    st1.close();
    catch(Exception e){e.printStackTrace();}
    getContentPane().add(jlh);
    getContentPane().add(jl1);
    getContentPane().add(jt1);
    getContentPane().add(jl2);
    getContentPane().add(jt2);
    getContentPane().add(jl3);
    getContentPane().add(jt3);
    getContentPane().add(jl4);
    getContentPane().add(jt4);
    getContentPane().add(jl10);
    setSize(900,700);
    setVisible(true);
    show();
    public void paint(Graphics g)
    g.setColor(Color.red);
    g.drawLine(0,300,600,300);
    class Ex implements ActionListener
    public void actionPerformed(ActionEvent evt)
    if(evt.getSource() == bt1)
    dispose();
    return;
    This code is incomplete. The program is compiled and Ran. I am unable to see the Line.
    Is it because , I am using contentPane ?. Please help me to cake it clear.
    mjava

    I have no idea what JTutor is, but if it tells you to override paint() in Swing, it's not worth its disk space.
    [http://java.sun.com/docs/books/tutorial/uiswing/painting/closer.html] clearly says that for all practical purposes paintComponent will be the only method that you will ever need to override.

  • It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is

    It's simple... I want the Illustrator pen tool to ALWAYS make corner annchor points and NEVER smooth.  Right now I have to convert every single one of them, or I have to do a work around every time I draw a line and make one of the handles disappear.  Is there some simple setting out there that will just "make it so?"@

    The video I am watching this guy is just dragging every line to make curves.  And every anchor point is a corner.  He is not switching back and forth between the pen and the anchor points tool, and he is not using the convert points tool.  He draws a curved line and starts another straight line only to curve it with a click and a drag.  It is super efficient, and I could save a world of time if I could figure out what he is doing.

  • Drawing dashed line or dotted line in a flex line chart

    Friends,
    I want to draw a line chart which should be either dotted or dashed.
    since there is no component like dashed line chart, can anyone help me in creating one.
    i think if i extend the line series component, then i can draw that.
    but am stuck there. pls help people.
    Regards,
    Anoop

    Try looking [url http://www.macdevcenter.com/pub/a/mac/2002/03/22/vertical_text.html]here.
    : jay

Maybe you are looking for

  • Can't download itunes - security zone policy error message - please help!

    Hi there, I have had an ipod for a while now but can't use it as everytime i try to download itunes I just get the following error message; This download has been blocked by your security zone policy - edgesuite.net. I am using firefox on a windows v

  • Change documents with persistent class

    Hi, I have created a persistent class and want to use a set-method to change data in the mapped table - nothing special. But: Does anybody know if there's a possibility to write change documents for the changed field without calling FMs like CHANGEDO

  • Report painter: Financial statement debit credit indicator taken into account?

    Hi, When I create a report with report painter (FGI0) It does not take into account the debit / credit indicator of the FS statement. Is this standard SAP or do I miss a setting? kr, Klundert

  • Counter on my blog

    My counter should have turned over to 10,000 today. Instead, it went back to 1000! What can I do to fix this?

  • How to extend the fields length

    Hi Experts, I want to increase the fields length of my BP name in portal . now it is 40 char in one line but i want 60 char in one line .Can any body send the solution. Thanx in advance Regards, Khurram