Drawing a straight line

Hello,
I haven't been able to draw a straight line in a JPanel as a separator. I mean, I have several other componentes in the JPanel and I would like to use straight lines as separators between some of the componentes. Besides drawing the line, how could I set its length?
Thank you,
Alfredo

You could use a JPanel and set its border to a LineBorder (or whatever border you desire. Then set the preferred size of the panel and all that gets painted is the border.

Similar Messages

  • How to draw only straight line instead of angled one??

    Dear friends,
    I saw a very good code posted by guru here(I think is camickr),
    But I tried to change it and I hope to draw only straight line instead of angled one, can you help how to do it??
    Thanks so much.
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DrawingArea extends JPanel
         Vector angledLines;
         Point startPoint = null;
         Point endPoint = null;
         Graphics g;
         public DrawingArea()
              angledLines = new Vector();
              setPreferredSize(new Dimension(500,500));
              MyMouseListener ml = new MyMouseListener();
              addMouseListener(ml);
              addMouseMotionListener(ml);
              setBackground(Color.white);
         public void paintComponent(Graphics g)
              // automatically called when repaint
              super.paintComponent(g);
              g.setColor(Color.black);
              AngledLine line;
              if (startPoint != null && endPoint != null)
                   // draw the current dragged line
                   g.drawLine(startPoint.x, startPoint.y, endPoint.x,endPoint.y);
              for (Enumeration e = angledLines.elements(); e.hasMoreElements();)
                   // draw all the angled lines
                   line = (AngledLine)e.nextElement();
                   g.drawPolyline(line.xPoints, line.yPoints, line.n);
         class MyMouseListener extends MouseInputAdapter
              public void mousePressed(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        startPoint = e.getPoint();
              public void mouseReleased(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             AngledLine line = new AngledLine(startPoint, e.getPoint(), true);
                             angledLines.add(line);
                             startPoint = null;
                             repaint();
              public void mouseDragged(MouseEvent e)
                   if (SwingUtilities.isLeftMouseButton(e))
                        if (startPoint != null)
                             endPoint = e.getPoint();
                             repaint();
              public void mouseClicked( MouseEvent e )
                   if (g == null)
                        g = getGraphics();
                   g.drawRect(10,10,20,20);
         class AngledLine
              // inner class for angled lines
              public int[] xPoints, yPoints;
              public int n = 3;
              public AngledLine(Point startPoint, Point endPoint, boolean left)
                   xPoints = new int[n];
                   yPoints = new int[n];
                   xPoints[0] = startPoint.x;
                   xPoints[2] = endPoint.x;
                   yPoints[0] = startPoint.y;
                   yPoints[2] = endPoint.y;
                   if (left)
                        xPoints[1] = startPoint.x;
                        yPoints[1] = endPoint.y;
                   else
                        xPoints[1] = endPoint.x;
                        yPoints[1] = startPoint.y;
         public static void main(String[] args)
              JFrame frame = new JFrame("Test angled lines");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              DrawingArea d = new DrawingArea();
              frame.getContentPane().add( d );
              frame.pack();
              frame.setVisible(true);
    }

    Change the AngledLine class to store two points instead of 3 points (I would rename the class to be StraightLine). The code is much simpler because you just store the starting and ending points and you don't need to calculate the middle point.

  • Is there a way to draw a straight line from one point to another?

    Is there a way of drawing a straight line from one point to another please?

    Yes.  First click on this icon:
    Now select the line drawing icon:
    Now press a shift key and drag your mouse on the image to draw a straight line.
    These instructions are for Windows system so you need to adapt the method for Macs.  I can't afford to by an Apple Mac!!!!!
    Good luck.

  • Drawing a straight line over a video

    Is it possible to draw a straight line over a video in CS6 and also to watch the video frame by frame to take exact timings?

    Hi Jeff,
    Back again! i have managed to put the line over the video and can have it on there as long or as short time as i wish, but it appears to be moving with the video and i need it to stay at a certain point and the video to carry on playing. Basically im trying to mark a point on a race track where the horse in the lead gets to, then i need the line to stay there for when the last horse comes to the line, with the lead horse moving on past. Currently the line doesnt stay on a specific point it on the video and go out of shot when the video moves, it appears to be moving with the video. I know the overlay is a static image but is there a way of making it look like it stays in a specific place on the video?
    Hope this makes sense!
    Thanks Kat

  • Any way to simulate a user drawing a straight line in Captivate 6?

    I'm trying to create a software simulation. While most of the user interaction with the software involves just clicking buttons and entering values in various fields, there is one place where the user has to draw a straight line from one point to another. Basically, I would like Captivate to dynamically display the line as it is being drawn (i.e., getting longer as the mouse moves away from the starting point).
    Is there any way this can be done in Captivate? Thanks.

    Hello,
    Welccome to Adobe Forums.
    Software Simulation (Automatic Recording) create slides on event based (Keyboard button press or Click on Mouse)
    When you draw something it will not show you the drawing at the time of recording, for that you can use Video Demo
    Thanks,
    Vikram

  • Can a Lightroom adjustment brush draw a straight line by clicking the start and stop points?

    Can a Lightroom adjustment brush draw a straight line by clicking the start and stop points?

    studioMac wrote:
    I'm trying to selectively adust areas of an image in Lighroom. eg: a window frame in an architectural photo, and so being able to make straight lines with the adjustment brush would be very useful.
    I agree it would be useful. It's something that's been asked for. The best thing is to keep requesting at the Lightroom feature request forum

  • How can i draw a straight line with a brush?

    i know the pencil tool can draw a straight line with anchor points. is there a setting for the pencil tool that can mimic a 30 point brush, low hardness (faded side to side) at about an 80 degree angle or is there a way to make a straight line with the brush tool using a mouse?
    i know this image is a bit blurry. what i want to do is replace the 2 white angled lines with the 30 point brush effect 230 pixels wide. the project on the left of the pic is a 2ft by 4ft canvas. any ideas? please help.

    Hello Mike, I wonder if you can help, no one else can. I asked this question on the forum in August Brush line fades on start with anchor points
    Only on Photoshop CC does this happen, drawing a diagonal line with shift key, instead of line starting dark & then fading out, it does the reverse, starts on nothing & then darkens towards anchor point. I am on trial versions & can't purchase until this is cleared up.

  • Flash CC 2014 Drawing with tablet creates straight lines

    I recently downloaded Flash and Photoshop from the free student service and when I use my tablet Intuos4, the lines you see are drawn but it's also draws in the far left, the start of the straight line is where I actually start but for some reason it draws a straight line shifting to the left.
    I checked if it was my shift key from the keyboard and tablet to see if it was jammed, but on the bottom half of the canvas you notice that when I do use my shift key it still draws straight lines and still goes to the far left.
    I updated my drivers for my tablet and it still didn't do anything, it doesn't happen to any other program like Photoshop, it detects the tablet and draws normally.
    Help please?
    http://oi59.tinypic.com/2r6igjq.jpg

    Hi.
    I am experiencing some serious issues with flash professional cc and my drawing tablet. Every time I place my drawing pen on the surface of my tablet, while in flash professional cc, a long straight line darting to the left and beyond my canvas occurs. I haven't messed with any of my settings for I just got the tablet today as well as the flash professional cc program. It's very frustrating and is hindering my work. If this problem is not resolved, I will take my business and money elsewhere.
    Thank you.
    All specs:
    Flash Professional CC 2014 v. 14.1.0.96
    Windows 7
    Monoprice Graphic Drawing Tablet 10x6.25 inch 4000 LPI, 200 RPS, 2048 Levels

  • CS6 - Brush bug - randomly draws straight lines when sketching

    Hey everyone,
    I noticed this bug that occurs when I use the brush tool. Whenever I'm sketching in a small region, it randomly draws a straight line, as if I never lifted my pen. It's like when you hold the shift key to make a straight line, except I'm not holding the shift key. However, this only happens if I'm drawing semi-closely and/or if I'm drawing semi-fast (not that fast though. The lines will connect even though I lifted my pen. Does anyone know how to fix this problem? I updated my video card and tablet to its latest drivers but it hasn't fixed the issue.
    Specs:
    Windows 7 64 bit
    Wacom intuos5 tablet
    Nvidia GT 520 Graphics card
    Photoshop CS6
    Any help would be appreciated.

    Allso have this from time to time.
    The brush loses response and does little short straight lines here and there, it's a software glitch. I usually save my document when that happens, this usually snaps it out of it but a few times I had to wait then save again. I used to be able to just swap apps or click on layers or something but that doesn't work anymore.
    XP 32bit
    CS5 32bit
    I had the same promlem with CS4 trial, with my old Manhattan tablet and with my new Intuo's. I think it's a bug that comes in from time to time with panel, window focus changes. Or Id get up to fetch a cup of coffee and when I come back it's like that.

  • I wan to use straight lines not arcs in smith plot

    The default display for smith plots in the Labview picture control is to connect each point with an arc. We would like to connect the points with a straight line. Where should we make the change and has this been done already?
    Michael Aivaliotis
    VI Shots LLC

    The smith plots are open for editing. I performed quick search and a lot a of digging to find that the lines are drawn with a VI called "Draw Clipped Arc.vi". I suspect that you can replace this VI with one for drawing a straight line. I recommend looking in the VI heirarchy. This VI is about 6 subVIs deep.

  • Can I draw a freehand line in a Fill & Sign document?

    Can I draw a freehand line in a Fill & Sign document? I have filled in the form but need to draw a freehand line to indicate the markings on our horse's face.

    Hi franc60007656,
    You can draw a straight line only in a fill and sign document and not a free hand line.
    Regards,
    Rahul

  • Photoshop CS5 brush randomly becomes straight lines

    Hi everyone,
    I'm having a problem with my student edition version of photoshop CS5. For some unknown reason the brush tool randomly stops drawing lines that I command it to do (using my tablet pen) and will correct itself when I open another program (any program). Instead of drawing a curve, it will just draw a straight line and half the time not even for very far. I cant figure out for the life of me what is causing this problem. My laptop isnt on stickykeys or anything like that and I am running windows 7 64 bit with 8 gig of ram..
    THANKYOU SO MUCH in advance if you can help a student in need of doing her homework!
    Kerryanne

    Allso have this from time to time.
    The brush loses response and does little short straight lines here and there, it's a software glitch. I usually save my document when that happens, this usually snaps it out of it but a few times I had to wait then save again. I used to be able to just swap apps or click on layers or something but that doesn't work anymore.
    XP 32bit
    CS5 32bit
    I had the same promlem with CS4 trial, with my old Manhattan tablet and with my new Intuo's. I think it's a bug that comes in from time to time with panel, window focus changes. Or Id get up to fetch a cup of coffee and when I come back it's like that.

  • How Do I Draw An Angled Straight Line?

    Hello,
    I'm restoring an old B&W photo of my Grandmother walking in Atlanta in around 1932. I'm trying to make the power lines of the trolley cars as realistic as possible. Consequently, I'd like to be able to draw these power lines better than they appear in the photo - I've cloned them in and tried to enhance them from the way they are originally, but they are not as straight and authentic as I would like them to be.
    Of course, I know how to draw a straight perpendicular or horizontal line, but is there also a way to draw them when they are at an angle?
    Where are you, Buko and Lundberg02 - Hope you guys are doing ok.
    Thanks for any help you can muster up.
    Burtron

    Scott,
    I just did it! And to think that I went all that time trying to draw those lines as steady as I could - Wow, I thought that surely Adobe would have a way. I just waited too long to get around to asking.
    What a difference this will make!
    Also, in this same old photo is a building that was torn down long ago, I'm sure, but it's after working with it a while, and using the contrast to bring out the images on this building, I began to realize that the building had more and more images - I mean all over it - It's amazing - I don't think that anyone these days would go to all the trouble that this guy did - whoever he is - That's my next challenge - I need to find out who this architect was. I've done all kinds of searches on google, but to no avail. Going to contact the state archives.
    Do you have any suggestions?
    Thanks Again,
    Burtron

  • Drawing straight lines

    Hi,
    in my programm I need to draw straight lines(I hope this is the correct translation for an infinit line). Is there a way of doing this?

    I just answered my own question.
    I checked Illustrator Preferences and under GENERAL: CONSTRAIN ANGLE, mine was set to 0.19 degrees (for reasons unknown).
    I changed it to zero and Voila! Who'd have thought this would alter the whole drawing surface?
    All I had to do was ask others in order to figure it out myself! Hope this helps anybody else having this bizarre problem.
    Vic.

  • Drawing small, short curves in Photoshop draws straight line between start and end points

    I recently installed Windows 8 Professional, Photoshop and the latest Wacom Bamboo tablet drivers and have been experiencing this issue. I've turned off windows flicks and ink. This only happens in Photoshop with the brush tool and I can't seem to find a setting that this corresponds to.
    Basically, when I draw small, short curves (particularly letters like 'c' and 'h'), when I lift up my pen, Photoshop automatically connects the end and start points together with a straight line ('c' almost becomes 'o' or 'a'). I'm not holding the shift or any modifier keys. I've tried googling this issue, but I have no idea how to phrase it properly to get any results.
    Here's an image of what I'm talking about (the top was drawn with the pencil tool, the bottom with the brush tool which demonstrates the issue. I've highlighted the start and end points with red dots):
    ANy ideas? :/

    Is caps lock on?

Maybe you are looking for

  • Custom icon leaf tree

    Hi developers, I have one how to do question: In a tree I like to introduce a custom icon on each leaf. For this, I tried to introduce at the icon column sql #WORKSPACE_IMAGES#picture.gif but nothing happened, instead if I use #IMAGE_PREFIX#standard_

  • Forte Estimating Metrics

    In his book Object-Oriented Software Metrics (Prentice Hall, 1994), Mark Lorenz in proposes an approach for estimating OO projects. Lorenz recommends the average amount of effort spent on a single class is the best indictor of the amount of work requ

  • Integrating Oracle APPS with APEX using popay_apex package...

    Hi, I am a newbie in APEX and tried to explore it only a few months back... I must admit that this tool is Awesome..!!! Also, I tried to integrate Oracle EBS 11i with APEX using [popay package |https://sites.google.com/a/popay.be/apex-on-apps/integra

  • Adobe Presenter tab does not appear in PowerPoint 2013

    Hello, I have a user who is using a laptop running Windows 7 (64-bit) and Office 2013 (64-bit). I installed Adobe Presenter (64-bit) for him, and it worked well until this week, when the Adobe Presenter tab disappeared. When I go into the Add-Ins, I

  • HT3529 Why is my messages sending green and not blue

    Why is my messages sending green and not blue