How to change draw dashed line with arrowhead (not straight)?

Hi friends,
The following code sinept draws an arrowed line from a given point to the other point. I want to know how it can changed to be dashed line as well? I would appreciate it if anybody help me for doing such changes.
Thanks in advance,
Reza_mp
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ArrowExample extends JFrame
    enum ArrowHead {
        HEIGHT(10), WIDTH(10);
        int n;
        ArrowHead(int n) {this.n = n;}
        public int value() {return n;}
    java.util.List<Arrow> arrows;
    BasicStroke stroke;
    private class Arrow {
        Point start;
        Point end;
        Polygon arrowHead;
        public Arrow(Point start, Point end) {
            this.start = start;
            this.end = end;
            double direction = Math.atan2(end.y - start.y, end.x - start.x);
            System.out.println(direction * 180/Math.PI);
            arrowHead = new Polygon();
            arrowHead.addPoint(0, 0);
            Point p1 = rotate(ArrowHead.WIDTH.value()/2, ArrowHead.HEIGHT.value(), direction);
            arrowHead.addPoint(p1.x, p1.y);
            Point p2 = rotate(-ArrowHead.WIDTH.value()/2, ArrowHead.HEIGHT.value(), direction);
            arrowHead.addPoint(p2.x, p2.y);
            arrowHead.addPoint(0, 0);
            arrowHead.translate(end.x, end.y);
        public Point rotate(int x, int y, double dir) {
            Point p = new Point();
            double r = Math.sqrt(x*x + y*y);
            double theta = Math.atan2(y, x);
            p.setLocation(Math.round(r*Math.cos(theta + dir + Math.PI/2)),
                          Math.round(r*Math.sin(theta + dir + Math.PI/2)));
            return p;
        public void draw(Graphics2D g) {
            g.drawLine(start.x, start.y, end.x, end.y);
            g.drawPolygon(arrowHead);
            g.fillPolygon(arrowHead);
    public ArrowExample() {
        super("Arrows");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel p = new JPanel() {
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2d = (Graphics2D)g;
                Stroke oldStroke = g2d.getStroke();
                Color oldColor = g2d.getColor();
                g2d.setStroke(stroke);
                g2d.setColor(Color.black);
                for (Arrow a : arrows)
                    a.draw(g2d);
                g2d.setStroke(oldStroke);
                g2d.setColor(oldColor);
        p.setBackground(Color.white);
        add(p, BorderLayout.CENTER);
        stroke = new BasicStroke(3);
        arrows = new ArrayList<Arrow>();
        arrows.add(new Arrow(new Point(10,10), new Point(100,100)));
        arrows.add(new Arrow(new Point(300,10), new Point(300,100)));
        arrows.add(new Arrow(new Point(450,450), new Point(400,100)));
        pack();
        setSize(500, 500);
    public static void main(String[] args) {
        setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new ArrowExample().setVisible(true);
}

Change the draw method as follows:
        public void draw(Graphics2D g) {
            Stroke s = g.getStroke();
            g.setStroke( new BasicStroke( 3.0f, BasicStroke.CAP_BUTT,
               BasicStroke.JOIN_MITER, 1.0f, new float[] { 10.0f, 10.0f }, 0.0f ) );
            g.drawLine(start.x, start.y, end.x, end.y);
            g.setStroke( s );
            g.drawPolygon(arrowHead);
            g.fillPolygon(arrowHead);
        }

Similar Messages

  • How can I draw dashed lines on a Picture Control?

    I have loaded a *jpg map onto a Picture Control.
    I then load a file of X-Y coordinates that make-up different legs which are connected.
    I need to make these lines dashed. Before I spend time on adding new points in between
    points and then alternate between "Draw line" &
    "Draw point", I wonder if there is an easier
    way of maybe changing the attribute of the
    line with "Draw Multiple Lines" ???

    I have been trying to draw dashed lines too. I have tried drawing a dash and then putting it in a loop. the loop executes after the user has lifted the mouse and then it gets the end point of the line. the problem is that the line appears only after the mouse has been pressed, dragged and released. I was wondering if you have managed to solve your problem. If yes then could you help me with it.

  • Can Flash create dashed line with blunt not rounded dashes ?

    Hi,
    using Flash8
    I can select line tool and dashed line in properties and draw a dashed line and get a line of sausages. How do I get a line of dashes without rounded ends to each dash ?
    Line option has end caps option with None (gives straight or blunt tip to line, round gives rounded tip .
    Draw a line with None and its got blunt ends, select it and choose dashed line option and it gets round ends to the dashes, the end cap option is greyed out !
    Are dashed lines with blunt dashes now possible again with CS4, a forum poster also found that CS3 no longer gave blunt dashes ?
    Why do I ask:-
    I am trying to bring a map into Flash8 from Illustrator (Illus version 10 as it allows blunt tip lines to remain blunt it was said on the forum)... which has blunt ends to roads and has blunt type dashed lines. The roads remain blunt..GOOD !..but the dashed lines become what looks like a solid line. BAD !
    I do a right click - break apart,  then double click one of those now solid lines that should be dashed, and I am able to select a portion of the line, it is no longer a continual line as drawn in Illustrator. Properties shows it as solid line. Flash8 obviously having a problem with supporting Illustrator 10 dashed line then !
    Select dashed in properties box and I get a portion of the line as sausage dashes, but working my way along the line doing each bit sees a far from correct dashed line result as sausages dont start stop evenly as each line is a separate entity and ignores the previous line.
    Looks like I shall have to try and draw the line as one long line again in flash but unless I can give it blunt dashes when done, there is no point even trying that method, hence my question.
    Would the latest Illustrator and Flash versions (CS4) allow blunt type dashed lines to appear in Flash ?
    This is crucial for bringing maps into Flash.
    Envirographics

    I noticed one problem with my solution.
    If you look, very carefully, at the end of the stream, it's flat. Not rounded like it should be. After a bit of trial and error, I tried a different brush:
    Note that, in addition to the rounded rectangle (done with the new corner controls in the latest version of Illustrator CC that just came out) and the three circles, there is also a rectangle, with no stroke and no fill, to provide a space at the end of the three dots. Here is the result:

  • How do you get a line with MULTIPLE fields to WRAP ?

    How do you get a line with MULTIPLE fields to WRAP ?
    Good afternoon everyone...
    THE PROBLEM: Why doesn’t a line with multiple fields WRAP?
    HYPOTHETICAL EXAMPLE/WHAT I”D LIKE TO SEE
    If I have 2 fields on a line (this is now a hypothetical example and nothing to do with my actual report)….let’s call them field A and field B. And if field A has values of all ‘X’ and field B has values of all ‘Y’…then….the normal case would be (ignore dots – only for spacing):
    A……………………… B
    XXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYY
    But what if A is too long? I would want to see B wrap onto the next line like this:
    A……………………………………………………B
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX YYYYYY
    YYYYYYYYYYYYY
    And similarly….if B is extra long, can the line print as:
    A………………………. B
    XXXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYYYYYYY
    YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
    I don’t want the case where B is long and I get:
    A………………… …B…
    XXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYY
    ………………………..YYYYYYYYYYYYYYYYYYYYY
    I can see how you can wrap an individual field like that…but how can you WRAP a line of[b] fields within the frame so it wraps to the BEGINNING of the frame on next line?
    My SPECIFIC CASE
    I have a report that I have stripped down to a simple structure for the purposes of this explanation.
    My DATA MODEL has the main QUERY (for plant family and species data). The columns of the query are divided into 2 groups. The 1st GROUP contains the family data. Below that is the rest of the species data in a 2nd GROUP.
    Linking from the 2nd species group (above) is a new QUERY to extract REGION data based on the common key field. Under this 2nd query is another group with all the REGION columns.
    The LAYOUT MODEL has a group frame (the main , base one)
    On top of this is a repeating frame based on the 1st group (family data).
    On top of this is another repeating frame for the 2nd group (species data).
    On top of this is 2 Frames on the same line line. The 1st frame contains columns from the species group .
    The 2nd frame on this line is a repeating frame. The PRINT DIRECTION for this frame is ACROSS/DOWN. It repeats details of the REGION where the species is found. These columns come from this group come from the REGION QUERY and GROUP.
    All fields on the report line have variable horizontal elasticity.
    The problem is that when there is too much data on the line, it does NOT WRAP to the 2nd line.. It TRUNCATES.
    Can the line be made to WRAP????..
    In my current report, 1 of 2 things is happening:
    1) All fields print on the line until it hits the page boundary and then it just stops. Truncated!
    2) All fields print on the current line, then Oracle Reports throws a new page to print the REMAINDER of the long, input line
    But I would like a LONG line to continue printing onto the following line of the same page.
    I have tried all combinations of the elasticity fields and the ‘ADVANCED LAYOUT’ properties.
    I have been focussing my attention with this problem on the frames .
    We are using REPORT BUILDER V 6.0.8.26.0
    Thankyou to anyone who may offer assistance.
    Tony Calabrese.

    Steve,
    you gain 1 thing, but you lose something else!
    This thing is SO frustrating!
    Hey Steve! Good afternoon.
    I've done as you suggested....I have a long text boilerplate item - the only 1 on the line...and it has all the column in it.
    So it looks like:
    &col1 &col2 &col3 &col4 &col5 etc etc etc
    And the line expands nicely to each field's requirements.
    And when it gets to the right page boundary...it WRAPS to the next line! Beautiful!!!
    The only thing is that...when I had individual fields across the line I was able to create format triggers for those fields. And in doing so I was able to reduce the font and change the justification. I had to do that because some of the fields had to appear superscripted.
    So I wanted something like (ignore the dots):
    ...................................ppppp
    AAAA BBBB CCCCC DDDD EEEE FFFFFF
    So the field of 'ppppp' appeared slightly higher on the line than the other fields...
    I can't see how I can do this with a single TEXT field containing all the &COL values.
    Have you ever come across anything like this?
    Thankyou again,
    Tony Calabrese 12/4/2007

  • Dashed line with jdk1.1.8?

    Hello
    Does anyone know how to make dashed lines with jdk 1.1.8? Yes, that means no Graphics 2D nor BasicStoroke class.
    Also how do you make the line wider with 1.1.8?
    I appreciate any response. Thanks
    michiko

    int lineLength = 100;
    for(int i = 0; i < lineLength ; i = i + 6){
    g.drawLine(i,i,i+3,i+3);
    how about that?

  • How can I draw a line in Preview without the arrow head

    Hello all!
    How can I draw a line in Preview without the arrow head at the end of the line?

    Yes. Once you select the line bar a new entry will appear where you can select what type of line. Based on my experience whether or not it will change is iffy.

  • How do I search for lines with a particular pattern and delete them when a match occurs

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 
    Lines in what? And what language are you using to develop with?
    Are the lines in a text file? A RichTextBox? A TextBox? Some other control? A List(Of String)?
    Is there some expectation by you that by providing what you wrote in your question post that the knowledge in your mind about what you are thinking about will mysteriously emanate to anybody reading your post so all of the sudden your knowledge will
    become their knowledge and they will be able to provide you with an answer as they will suddenly understand what you are trying to do? Because that's probably impossible. Most people try providing enough information in a question so anybody, even stupid people
    like me, can understand what they want. Maybe you should try that. As well as selecting an appropriate forum for your question in the future. Usually a question like this is related to programming in a particular language therefore a language forum may be
    a good choice. Or not.
    La vida loca

  • How can change my E-mail with out loss any thing ?

    how can change my E-mail with out loss any thing ?

    Calling was a good suggestion. Apple Care had the wrong email address and changing
    it for the Apple Discussions is not linked to Apple Care. The lady at Apple Care corrected
    the email address on my record.
    End of Shaggy Dog Story

  • We have version 10.5.8 photoshop CS3 for Mac. How do we fix a problem with photoshop not resizing dpi? For example we resized a 72 dpi image to 200 dpi, when we do a pdf analysis it read as 344 dpi.

    We have version 10.5.8 photoshop CS3 for Mac. How do we fix a problem with photoshop not resizing dpi? For example we resized a 72 dpi image to 200 dpi, when we do a pdf analysis it read as 344 dpi.

    Sounds like it's a problem with the Acrobat settings. Did you set them to the same resolution?

  • How to change the schedule line date in SO with reference to value contract

    Hi SD Guru's,
    I need to change the schedule line date in the sales order with reference to the value contract by using some algorithm that i will write. The problem that i can't find the suitable place to add the algorithm. I can't add it to the Copy control because there is no schedule lines in value contract and copy control for schedule lines does no exist.
    I can not add to user exit MV45AFZZ  , because order that was created with reference to the value contract, does not go through this user exit.
    Do you have some ideas where i can add it?
    Thanks and Regards
    Viky
    Edited by: Viky Sloutsky on Oct 20, 2010 12:43 PM

    Hello Viky
    How about using program MV45AFZB- USEREXIT_CHECK_VBEP or USEREXIT_MOVE_FIELD_TO_VBEPKOM
    or program FV45EFZ1- USEREXIT_CHANGE_SALES_ORDER
    Does the program go through these exits when an order is created with ref to a value contract??
    Also I am wondering why you need to change a Schedule line determined by Availability check and/or delivery scheduling?

  • Other Components Drawing Dashed Lines doesn't compile with Flex 4

    The lib was created in 2006 so it doesn't compile with Flex 4.
    The lib can be downloaded here http://www.quietlyscheming.com/blog/charts/dashed-lines/
    When compiling I get this error:
    Description     Resource     Path     Location     Type
    1136: Incorrect number of arguments.  Expected 3.     GraphicsUtils.as     /arrows/src/qs/utils     line 66     Flex Problem
    The line which doesn't compile:
    stroke.apply(target);
    How do I fix this error?

    I managed to compile the lib by rewriting the line:
    stroke.apply(target, new Rectangle(), new Point());
    But I don't understand what I have done.
    All Rectangle and Point dimensions are 0, but I'm sure it shouldn't be this way.

  • How to draw centre line with white background?

    Hi,
    I need to draw a centre line with white background on it. Now i'm doing it by pasting the main line in the background and giving it white so that it shows a white backgound. Is there a way to do just by drawing like normal lines. If we can, is it possible to control the white backgound only to show less than the original line in both ends. This is for illustrations i do for exploding views and i need to draw this line to show it as assembly drawing.
    Thanks
    Manoj

    1. Draw a white line segment of desired width (stroke weight) with round cap (Stroke panel) for the background line.
    2. Copy, Paste in Front
    3. Change to desired foreground color, butt cap, reduce stroke weight.
    4. Opt/Alt–drag foreground segment to overhang background segment by desired amount on both ends.
    5. Select both segments and drag to Brushes panel, choose Art Brush.
    6. In Art Brush Options choose Stretch Between Guides, drag guides somewhere to the inside of curve of round caps. (If in step 3 you chose black, set Colorization Method to Tints. Then you can select any color for the foreground segment by setting the stroke color.) Name the brush as you choose. Click OK.
    7. Draw any path and apply the brush.

  • How to change length of line in Photoshop CS3

    I must be being really stupid, but I can't find out how to change the length of a line I've drawn in PS using the line tool. Can anyone help me out?

    Which type of line did you draw?
    Filled pixels, Shape Layer or Path?
    If filled pixels, then it's just like with any other pixelsyou have to erase them, or or make a selection and delete them. To lengthen, you'll have to use the Transform function.
    If you created your line as a Shape Layer or as a plain path, they are both defining the line as vector elements. If you look very closely, you'll see that the line is actually a thin rectangle-shaped patha boxif you will.
    In this case you can use the Path Selection Tool to select two of the anchor points and move them manually, or you can select the entire path and then use the Transform Path function (Command + T) and input values in the Options Bar to transform the points numerically.

  • How to create a dashed line for cell border

    Hi,
    Is anyone know How to apply the style for cell border to get the dotted line in WinRT 
    In WPF i will get the dotted line for cell border using this way.
    <DrawingBrush Viewport="0,0,20,20" ViewportUnits="Absolute" TileMode="Tile">
    <DrawingBrush.Drawing>
    <DrawingGroup>
    <GeometryDrawing Brush="Black">
    <GeometryDrawing.Geometry>
    <GeometryGroup>
    <RectangleGeometry Rect="0,0,50,50" />
    <RectangleGeometry Rect="50,50,50,50" />
    </GeometryGroup>
    </GeometryDrawing.Geometry>
    </GeometryDrawing>
    </DrawingGroup>
    </DrawingBrush.Drawing>
    </DrawingBrush>
    Thanks in Advance,

    check this thread: 
    http://stackoverflow.com/questions/14673643/windows-store-apps-how-to-draw-a-dashed-line
    Fouad Roumieh

  • Writing text vertically and drawing dashed line

    Hello,
    I m trying to write text vertically ( basically to write data on the y-axis of a graph)..Is there a way in which i can set the line direction properties to VERTICAL..?
    Also, i m trying to draw a dashed line.Can anyone tell me how to do this?
    Thnx in advance....

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

Maybe you are looking for

  • OBI Configuration issue in P6 8.3

    Hi, We have installed the OBIEE 11.1.1.7 and primavera p68.3 And configured the OBIEE with Primavera. While clicking the reports tab in primavera application its showing an error like "No Data is available because your p6user name is not valid for co

  • How to validate Date value in Text Column

    Hi All, I have entered DATE value in text item field(Char Data Type), Now how can i validate, the entered date is valid or not. Thanks in advance.

  • Creating Infocube

    Hi, I am trying to create infocube in SAP BI 7.0 but facing a lot of problem.As I donu2019t have screen shot to refer. I am referring SAP BW composed by fufu but it is mainly focused on sap bw old version. Can any one send me all the steps along with

  • ABAP Code Required to remove #

    Hi, I have 2 characteristics 0COORDER and 0WBS_ELEMT value for which do not exist for all the data records. As a result I get # in the report. How do I replace # in the report with blank? I don’t want to use the VB Script, need a permanent fix. Where

  • RAIDS and Time Machine?

    I want to get a Mac Pro with 4 500 GB HDs. I want to stripe two of the HDs together, and then stripe the other 2 together giving me two RAID 0's of 1 Terabyte each. Then can I use Time Machine when it is released to backup the primary RAID to the sec