Problem with dashed strokes

I have a GeneralPath that I draw with two different BasicStrokes.
The two strokes are (intended to be) identical except that one is
dashed.
What I'm observing is that in some cases the two stroked outlines
do not overlap, as I'd expect them to. Are my expectations incorrect?
I'm including a simple program that demonstrates the problem.
You can find a (blown up) screen capture here:
http://cradle.brokenglass.com/images/dash.png
This is occurring with (at least) the following:
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Thanks in advance.
-David
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class DashTest extends JFrame {
    class BoxCanvas extends JPanel {
        Stroke      dashStroke_;
        Stroke      lineStroke_;
        Shape       shape_;
        BoxCanvas() {
            BasicStroke ds = new BasicStroke();
            lineStroke_ = ds;
            dashStroke_ = new BasicStroke(
                ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(),
                ds.getMiterLimit() , new float[] {8, 8}, 0
            shape_ = makeShape();
            setBackground( new Color( 0, 200, 0));
            setPreferredSize( new Dimension(100, 100));
        private Shape
        makeShape() {
            GeneralPath p = new GeneralPath();
            p.moveTo( 20.0f, 70.0f );
            p.lineTo( 70.9f, 70.0f);
            p.lineTo( 70.9f, 20.0f);
            p.lineTo( 20.0f, 20.0f );
            p.closePath();
            return p;
        public void
        paintComponent( Graphics g ) {
            super.paintComponent( g );
            Graphics2D g2 = (Graphics2D) g;
            g2.setStroke( lineStroke_ );
            g2.setColor( Color.BLACK );
            g2.draw( shape_ );
            g2.setStroke( dashStroke_ );
            g2.setColor( Color.WHITE );
            g2.draw( shape_ );
    public DashTest() {
        super( "DashTest" );
        JPanel canvas = new BoxCanvas();
        getContentPane().add( canvas );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    public static void
    main( String[] args ) {
        DashTest app = new DashTest();
        app.pack();
        app.setVisible( true );

Here's the solution:
http://swjscmail1.java.sun.com/cgi-bin/wa?A2=ind0307&L=java2d-interest&F=&S=&P=953
In case that gets moved, the trick is to either turn on antialising:
  g2.setRenderingHint(
     RenderingHints.KEY_ANTIALIASING,
     RenderingHints.VALUE_ANTIALIAS_ON
  );or to set the line width to 1.01:
  BasicStroke ds = new BasicStroke( 1.01f );-David

Similar Messages

  • Problem with dashed line spacing when printing to pdf

    Hi all,
    this may be a problem with my pdf program (I use bluebeam), but maybe someone will have an idea how to fix it whether in indesign or bluebeam.
    so I made a dashed line using the stroke command in indesign. I need to have the spacing set to 3pt dash and 2pt space. I also need to keep the lineweight to 0.5...this all works fine and appears correctly in indesign when I preview
    the problem is that some of the dashed lines, but not all of them, change size and spacing in the pdf when I view it. it seems to change when I zoom in and out as well. I thought maybe this was just some odd feature with bluebeam and it would still print to the correct size, but it does not, it prints the lines as different sizes. does anyone have an idea why this happens and how to fix? ive viewed and printed from adobe reader and it seems to be okay there but this file will be accessed by multiple other people and they may not be opening and printing in adobe reader..
    thanks guys

    When you export a PDF you will notice that you are exporting to Adobe PDF. Using any reader beyond Acrobat Pro or Reader is a crapshoot.
    For issues with Bluebeam I suggest you contact the developer.

  • Problem with '-' (dash) in BEx web analyzer

    Hi All,
    we are having a strange problem with 0BPartner and 0Material. Our BPartner and Material have '-'(dash) sign as part of key. While selecting this BPartner/Material in Bex Analyzer, we do not have any problem, but when we try to select the same Bpartner/Material in BEx Web Analyzer, it puts an escape char in from of the dash. For eg:
    If i select the Bpartner "1234-5467" then in Web Analyzer selection box, it is displayed as  "1234\-5467" in the selection screen.
    If i do a search on 1234-5467, it returns zero value.But if i do a search on 1234\-5467, then i get the search hit.
    If i enter the Bpartner in the selection window directly and If i do not put the escape char, then it considers the input as range 1234 - 5467 and returns me no value in the report output.
    Has anyone had this type of issue? Please respond.
    Thanks
    Niveda

    Thanks Olivier,
    Sorry if you had misunderstood my question. They are 2 different Info objects. and i am having problem searching values in each one of these info objects.
    Let me explain it with an example.
    Scenario:
    Let say company defines material in the following format.
    "123", "456", "788", "345"....etc.
    And I have a report which has material as input selection.
    To run this report with single material i enter "123" in the selection screen
    To run this report with a range of materials, I need to enter 123 - 456 in the selection.
    I have no Issues
    Scenario 2.
    Consider a case if the materials are defined in SAP as "001-1234", "987-234"
    "123-234" etc.
    In this scenario, to run the same report for 1 material, i will enter 001-1234. But now the question is how will BW system interpret this material entry.
    Is this 1 single material(001-1234) or a material range (001 - 1234)??
    We have issue here. The system considers this material "001-1234" as a range (001 to 1234) instead of single material and gives me zero output.
    Any help??
    Niveda

  • Subject decoding problem with dash '-'

    When trying to decode a raw email with the following subject with MimeUtility the charactersequence =96 is not decoded correctly.
    When printed to the console a strange square box is drawn. When the same string is persisted to our database, the box ends up as a ? (questionmark) in the textfield.
    Subject: =?ISO-8859-1?Q?ICQ=2C_MSN=2C_AOL=2C_Yahoo!_Alle_Messenger_in_einem_Programm_=96_kostenlos!?=
    Edited by: markward.schubert on Aug 25, 2009 1:51 AM

    markward.schubert wrote:
    When trying to decode a raw email with the following subject with MimeUtility the charactersequence =96 is not decoded correctly.
    When printed to the console a strange square box is drawn. When the same string is persisted to our database, the box ends up as a ? (questionmark) in the textfield.
    Subject: =?ISO-8859-1?Q?ICQ=2C_MSN=2C_AOL=2C_Yahoo!_Alle_Messenger_in_einem_Programm_=96_kostenlos!?=The character with byte 0x96 in ISO-8859-1 is a control character (specifically SPA or Start of Guarded Area), so it cannot be decoded to a visible character. Most likely the encoding is actually WIN1252 (or CP1252), where 0x96 is a broader version of a dash. See [http://en.wikipedia.org/wiki/ISO_8859-1#ISO-8859-1] and [http://en.wikipedia.org/wiki/Windows-1252]

  • Problems with stroke thickness

    Hi, I'm having a problem with my stroke tool setting in Illustrator CS5.   When I try to use 0.5 for the stroke thickness I get 
    something literally 3 times the size of THIS .    So, I was wondering what I could be doing wrong, because I know that it's not supposed to
    turn out like that.
    Thank You for your help,
    RjoyD

    Thank You
    very much Jacob, for your help. I tried your suggestion and switched my stroke to mm as opposed to inches (I'm still learning ) and it looks like it should appear now. I believe my problem has been resolved.
    I hope you have a good day!

  • Having problem with applying layer style "stroke" to group

    - Windows 8.1 / 64bit
    - i3-4150 / 4GB / Geforce GTX 750 TI
    - Photoshop CC 2014
    Hi!
    I don't know why, but there is some problem that applying layer style "stroke" to group.
    When i make a group with some layer and apply to group a layer style-stroke with inside option,
    the strokes looks like grid are generated inside.
    Why i said that stroke cross to ㅎrid, because it looks like grid if i make that group bigger.
    (that black square is 'Rectangle 1' layer. Just resizing bigger than before)
    Does anyone have same problem with me?
    Please, I need your help..

    pillfish wrote:
    I am having the same problem. it happens every time in cc and cc 2014. I am back using cs6. Which seems to run better on the whole.
    That's interesting. And this is happening with CC and CC 2014?  Do you have all the updates for the Photoshop CC versions?
    I've just tried to duplicate it without success, (windows 7, GTX570) so I wonder if there is a condition that triggers it?  Unfortunately, with this being such an old thread, the only person still around is R Kelly.
    OK, I just thought to try it on my Cintiq Companion 2, which has Windows 8.1 and Intel 5100, and the bug occurred. I actually got as far as firing up my Win 8.1 laptop before remembering that I had to sign out of CC to put it on my Cintiq, so I only have CS6 on it.
    Anyway....  looks like the bug is still there.  Are you using Win 8.1?

  • How to solve illustrator cs6 save as cs5 problem about the stroke(when the stroke with clipping mask and color is gradient, save as cs5 will change to embed ).

    how to solve illustrator cs6 save as cs5 problem about the stroke(when the stroke with clipping mask and color is gradient, save as cs5 will change to embed ).

    Because it was not possible to apply a gradient to a stroke in CS5. When you open the file in CS5, it is reduced to something that can be rendered in CS5.

  • Problem with illustrator cs3 : stroke

    Escribe texto o la dirección de un sitio web o traduce un documento.
    Cancelar
    hi, i'm new in illustrator and i have a problem with it; when i choose in stroke 0,75 or less than 1, i can't change it, but when i choose more than 1, it changes. I select the whole picture but it still does not change.
    I hope that tou can help me with this problem.
    thanks

    Go into the Transform panel and uncheck the box that says Align to Pixel Grid. It is new to CS5 and on by default.

  • Problems with "no color" in the "Fill and Stroke"

    I am having problems with “no color” in the “Fill and Stroke” function of Flash CS4 Pro.
    I had been using CS4 for 10 days and everything worked fine. Then I tried experimenting with various color combinations (along with “no color”) for “Fill and Stroke” for a simple button. Suddenly CS4 locked up on me while I was working with the “color panel”. A second color panel appeared in the upper left corner and the program was not responding. All I could do was to end the CS4 task.
    After that, whenever I created even a simple rectangle, at first the colors would appear as indicated for “Fill and Stroke”, but when I selected the object to see its properties, either the stroke or the fill color box would have a red slash line, indicating a “no color”, and I couldn’t select the color box to change it using the ink bottle tool, although the other box worked fine.
    Rebooting did not help. So I uninstalled CS4 (and didn’t keep the preferences), rebooted, then reinstalled it. The problem was still there. Logging on as another user didn’t help. I tried restoring the Windows system to before I installed CS4 and resinstalling it and that didn’t work. I have a disfunctional CS4 now and I don’t know what to do to fix it. Please help me. Thank you.

    Have you updated flash to 10.0.2?  Have you played around with a bunch of different selections, objects, and so forth to see if this box is always incorrect?  I think there's some particular selection (order of selecting things, and so on), where the color swatches in one location don't work as expected. However, it should not happen all the time and from what I recall it was fairly easy to work around (I can't even figure out what this was - so probably not it, as it seems hard to run into or perhaps now fixed).
    Also make sure you have the stroke selected - if you don't have everything selected, either the fill or stroke will show no color and dim depending on the selection.

  • Problem with my Library Program (mouse clics and keyboard strokes not work

    <blockquote>Locked by Moderator as a duplicate/re-post.
    Please continue the discussion in this thread: [/forum/1/688186]
    Thanks - c</blockquote>
    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    I work in a library in Saint-Raphaël France. We have a full web program placed on our server named Vubis Smart (Infor Society) to manage the books (our database). When using Firefox to access from remote machines every 3 mouse clics, only one is functional ; second problem when i type on the keyboard every 3to6 letters, a letter did not appear. With Microsoft internet explorer no problems. This problem appears only in our computers (not in the other libraries). Windows vista pro sp2. Dual core e5300, RAM2Go. Antivirus Trend Office Scan. How can i analyse this fact ? Thanx for your help, as i realy want to use Firefox instead of IR(Bleahh).
    == This happened
    ==
    Every time Firefox opened
    == we started using Firefox
    ==
    == Troubleshooting information
    ==
    no extension used. Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6
    == Firefox version
    ==
    3.6
    == Operating system
    ==
    Windows Vista
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6
    == Plugins installed
    ==
    *-Default Plug-in
    *Shockwave Flash 10.0 r12
    *Picasa plugin
    *3.0.50106.0
    *Windows Presentation Foundation (WPF) plug-in for Mozilla browsers
    *Java Plug-in 1.6.0_11 for Netscape Navigator (DLL Helper)
    *Java(TM) Platform SE binary
    *Adobe PDF Plug-In For Firefox and Netscape
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site.

    i solved my problem myself  !!
    you have to reset NVRAM  and  SMC  on your macBook !
    you can find the instruction by search in apple website .!

  • Simple dashed stroke in illustrator with javascript?

    I just need to get started understanding the dashed stroke portion in path drawing in illustrator.
    Any clues? Thanks in advance.

    what Larry said
    var idoc = app.activeDocument;
    var ipath = idoc.selection[0]; // select your path
    alert(ipath.strokeDashes.toSource()); // read the current dash/gap settings
    ipath.strokeDashes = [2,3,2,1]; // change it to your needs

  • [JS/CS4] What's up with the Stroke Styles?

    Pondering the possibilities of Marc Autret's fantastic ScriptUI Image Injection trick (
    get swatches in dropdown list with color preview... ) I wondered if it was possible to do something a bit more complicated -- a Stroke Style dropdown, with a custom image per stroke style (dashed, dotted, striped), just like the Real Thing. But ... I'm stopped dead in my tracks by one simple nagging problem. Where did the stroke styles go?
    According to my documentation, both Application and Document should have a strokeStyles property, listing all of the available stroke types, and separated dashedStrokeStyles, dottedStrokeStyles, and stripedStrokeStyles properties, to gain access to each of the separate types. However, *all* styles report their length  as "18" and can give me their names but nothing else (dashArray, for example, fails on non-dashed strokes and returns nothing at all for the dashed ones). And the separate lists all seem to have a length of 0. And all of the strokes' "strokeStyleType" ought to return a useful descriptor name but return "" (empty string) instead.
    alert (app.strokeStyles.length); // 18
    alert (app.stripedStrokeStyles.length); // 0!
    alert (app.dashedStrokeStyles.length); // 0!
    alert (app.dottedStrokeStyles.length); // 0!
    Is this my InDesign Gone Bad?

    function(){return A.apply(null,[this].concat($A(arguments)))}
    As far as I know, those 18 styles are built-in styles. You can't delete them, edit or whatever...
    Sure -- but I was hoping to at least see them in a script! It seems I cannot read *any* property out of them ??

  • Problem with swatches

    I am having trouble moving swatches into the swatch window so I can use them to fill as a pattern.  Most of the time I can move the swatch into the swatch window, but sometimes they won't work -- I've only experienced this problem with CS6 -- never in the earlier versions.  thanks

    You may have an offending element (dashed stroke, placed image). For example this one wont work
    Did you place an unfilled, unstroked bounding box behind the lines to create a pattern tile?
    Try drawing a simple rectanlge and making a pattern swatch, if that works, most likey you have an offending element.
    The reason the example I gave does not workj is the stroke is a pattern, so nested pattern.

  • Bug Report: line doubles dashed stroke

    Hi,
    to reproduce the bug, you have to:
    1. create a line with the line tool (I have used a weight of 1px and a lengt of 960px)
    2. give it a dashed stroke of the same weigt as the line weight. (1px in my case)
    3. Give it a dash and a gap width and set align on inside (4px / 4px in my case)
    Now you would expect a line with 4px dashes an 4px gaps, but you get a line with 7px dashes and 1px gaps.
    The problem lies in the creation of the stroke.
    The 1px stoke is basicly a 1px x 960px rectangle, because of that, the stoke goes all along the inside of the rectangle and creates two strokes on top of each other.
    This can be illustrated when you put the alignment of the stroke to outside.
    This behavior is fine for boxes, but in the case, where the line weight equals the stroke weight this behavior is a big problem.

    Since the line tool actually makes a skinny rectangle, you might try using the pen tool in shape mode to create a dashed line that will render as expected.
    If you select no fill, dashed stroke of selected color, 4 dash, 4 gap (similar to your example above) in the stroke options>more options, you will create a dashed line with equal spacing.
    Will that work for you?
    Pattie

  • Dashed Stroke not working on Image Traced image?

    So I'm able to use the dashed stroke normally if I create my own lines or shapes, but I'm using an image that I have image traced, expanded, and ungrouped, and I'm able to change the weight of the stroke and the brush but not apply a dashed stroke or a different brush profile, but I'm more concerned with the stroke. I haven't forgotten the gap.. What's up? Does it just not work on image traced stuff?

    What tracing method did you use?
    If the trace produced compound paths it is likely that you have also got duplicate paths.
    You need to analyse the trace to see where the problem lies.
    There is nothing about traced stuff that prevents the use of dashed strokes but if there are compound paths be aware that the compounds in their entirety will have dased stokes.
    You may need to release compound paths (with the hassle that involves) to get what you want.

Maybe you are looking for

  • Vendor Rating

    Dear All.                  Please any one tell me standard vendor rating report available in sap or not.. if yes please tell me the T-code for that and procedure REgards Kumar

  • Foreign character set problem

    Hi Sergiusz, it looks like you are a character set guru. Maybe you would know how to solve my problem? I've got a working application under oracle xe, apache and embedded listener. I would like to switch to a new APEX listener with tomcat but there i

  • Creative MuVo v100 cleaning

    Creative MuVo v00 cleaning So I have the Creative MuVo v00, gb model. I've had this mp3 player for many years, and enjoy it greatly. It still plays music fantastically, and I love the design. I wish they still made mp3 players with this design. I wou

  • HT1311 I live in Poland and I want to have the French itunes store, is that possible?

    I live in Poland and I want to have Frencj itunes in order to buy films and books in french, can you pls help me? Thank you.

  • Microsoft Access + Mac

    I have a teacher who is asking if he can purchase Microsoft Office with Access for his Mac. Has anyone got an answer? Or, better yet, is there a Mac software that is comparable to Access or File Maker Pro but easier to use? Just picking your brains.