How to make L-shaped lines?

Hi all,
as I'm rather new to Java I'm facing the follwing problem:
I've managed somehow to draw some lines on a JPanel. Now I'd like to click on any line and after the click a little point should appear on the chosen line. Then, dragging that point, the straight line should become an L-shaped line.
Again, as I'm new to Java I really don't know how to perform this task.
Any pieces of code, suggestions or whatever are highly appreciated.
Thanks in advance,
Hannes

Hi Hannes,
I am still not sure about what you want but this should help you with the techniques you might need. Please look at this applet and let me know.
Duke dollars are highly appreciated... :)
Berk Can Celebisoy
public class ForumTest extends JApplet {
  public void init() {   
    getContentPane().add(new CustomPanel());
class CustomPanel extends JPanel {
  int x1, y1, x2, y2, x3, y3;
  Graphics g_;
  public CustomPanel() {
    x1 = 10;   y1 = 10;
    x2 = 10;   y2 = 90;   
    addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {       
        x3 = e.getX();
        y3 = e.getY();                       
    addMouseListener(new MouseAdapter() {
      public void mouseReleased(MouseEvent e) {        
        g_ = getGraphics();
        //draw the conecting lines
        g_.drawLine(x1, y1, x3, y3);
        g_.drawLine(x2, y2, x3, y3);
        //draw the rectangle
        g_.drawRect(x3-2, y3-2, 4, 4);                     
      public void mousePressed(MouseEvent e) {       
        repaint();        
  public void paintComponent(Graphics g) {
    //draw the initial line.   
    g.drawLine(x1, y1, x2, y2);    
    //draw the rectangles
    g.drawRect(x1-2, y1-2, 4, 4);
    g.drawRect(x2-2, y2-2, 4, 4);
}

Similar Messages

  • How to make the diagonal line in the swing table cell?

    Hi all,
    How to make the diagonal line in the swing table cell just like the link below?
    http://61.132.17.188/webber/table.gif

    One improvement.. To get a line that is neat, use a bit of Graphics2D
        public void paintComponent(java.awt.Graphics g)
            int w = getSize().width;
            int h = getSize().height;
            // draw a line between (0,0) and (w,h)  
            g.setColor(getForeground());
            if (strTop == null)
                strTop = "  ";
            if (strBottom == null)
                strBottom = "  ";
                java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
              g2.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
              //g2.setStroke(new java.awt.BasicStroke(14.0f));
            g.drawLine(0, 0, w, h);
            //the following lines will draw the two strings,
            //one above the top of the line and the above below it.     
            g2.drawString(strTop, (w/2)+2, (h/2)-2);
            g2.drawString(strBottom, 2, (h / 2) + 2);
            //the x,y for drawString are only based on assumption.   //do necessary changes to suit ur needs.
        }Then create a TableCellRenderer and set it to the Table Header for ur table's 1st row.....
    Cheers

  • How to make the last line of the textarea visible all the time?

    Hello,
    I am making an online chat application in JSP and XHTML. The chat log and online users� names textareas are refreshed every 5 seconds. When it comes to many messages in the chat log textarea, the scrollbar appears. Then, every time the chat log textarea is refreshed, I need to move the scrollbar down to see the last line of the textarea.
    Are there any ideas how to make the last line of the textarea visible all the time without moving the scrollbar?
    Thanks in advance.
    Dan

    I put the below code on the page, but it didn't work.
    Are there any ideas? Thanks.
    <table border="0" cellspacing="1">
    <tr>
    <th>Chat Log</th>
    <th>Users now online</th>
    </tr>
    <tr>
    <td><textarea rows="20" cols="60" name = "messages" readonly = "readonly"><%= texts %></textarea></td>
    <td><textarea rows="20" cols="20" name = "names" readonly = "readonly"><%= names %></textarea></td>
    </tr>
    </table>
    <script type="text/javascript">
    <!--
    document.messages.scrollIntoView(false);
    //-->
    </script>

  • How to make a straight line of points in a curve in CS6

    In PSCS5 and earlier, I used to be able to make a straight line of points in a curve by placing 9 points on the straight line curve.  I did this by drawing a small straight line at the bottom of the curve using the pencil tool and then clicking the curve point icon.
    I can't seem to do this with CS6.  Any thoughts?
    Thanks,
    Matthew Kraus

    Did you not ask a similar question a while ago?
    http://forums.adobe.com/message/4524084#4524084

  • How to make a horizontal line in java html browser?? without hr

    I use java html browser
    I want to make a black horizontal line
    the <hr> line is not good
    for my customer it seems that there is a double spacing in this case
    I tried to write
    <td style = "BORDER-BOTTOM: 1px solid #000000"> ...
    but it does not work
    I suppose this style is not supported by the default StyleSheet
    I tried to write
    <td bgcolor="black" height=1>
    but the table has all rows with equal sizes
    therefore the real height is too big
    Please help me
    I tried to write
    <table border="1">... </table>
    even in this case I have table without any border

    Hi,
    the best way might be to use a blind table with all cells set to have a border on the bottom. The problem is that the standard Java runtime does not render such setting automatically. There is plenty of work involved to adapt it and still it then would work only in the adapted version and not the standard runtime environment.
    Anyway, you can find a working example of how to accomplish individual borders around table cells in open source application SimplyHTML at http://www.lightdev.com/dev/sh.htm
    Ulrich

  • How to make a new line item appear in a sales order in VA01 transaction?

    Dear All,
    I am trying to create a SO with single line item with quantity 100.
    Upon hitting the 'Enter' key, if the available quantity is less than the requested quantity (say 20), it takes me to an availabilty control screen which has a push-button 'One-time delivery' on the application tool bar.
    Upon clicking on this button, it takes me back to the main screen of VA01 where I currently see only one line item with quantity 100 and confirmed quantity 20.
    My requirement here is to make two line items appear, one with quantity 20 and the other with quantity 80, once I navigate back to the main screen of VA01 after clicking on the push-button 'One-time delivery'.
    Please provide me your valuable inputs. Any kind of help is highly appreciated.
    Useful answers never go unrewarded.
    Regards,
    Sreekanth Reddy B.

    Hi Sreekanth ,
    creating line items based on the confirmation qty can be done thru config, not thru ABAP,standard SAP will gives you options to create a new line item for unconfirmed qtys.
    check with ur functional consultant or try to post in SD /APO forums.
    regards
    Prabhu

  • How to make the Time Line in Vertical ?

    Hi All
    I have created a Schedule Board using the Schedule Viewer but
    including the Flexlib in my project .
    Now the thing is that the Timeline which us to come on the
    top of the
    ScheduleViewer I need to get that Time line Vertically in
    left side
    of the ScheduleViewer to display the time in left side,and
    all the
    date's in the top .
    How can I do that to get the Timeline Vertically and the Date
    at the
    position of TimeLine .
    Thanks
    Vivek Manchanda
    Theikos IT Solution

    One improvement.. To get a line that is neat, use a bit of Graphics2D
        public void paintComponent(java.awt.Graphics g)
            int w = getSize().width;
            int h = getSize().height;
            // draw a line between (0,0) and (w,h)  
            g.setColor(getForeground());
            if (strTop == null)
                strTop = "  ";
            if (strBottom == null)
                strBottom = "  ";
                java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
              g2.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
              //g2.setStroke(new java.awt.BasicStroke(14.0f));
            g.drawLine(0, 0, w, h);
            //the following lines will draw the two strings,
            //one above the top of the line and the above below it.     
            g2.drawString(strTop, (w/2)+2, (h/2)-2);
            g2.drawString(strBottom, 2, (h / 2) + 2);
            //the x,y for drawString are only based on assumption.   //do necessary changes to suit ur needs.
        }Then create a TableCellRenderer and set it to the Table Header for ur table's 1st row.....
    Cheers

  • How to make an anchored line for a sign-up sheet?

    I work for a small non-profit, and, as such, I wear many (too many?) hats.  I have no other experience with Adobe products (except for a very short intro class to InDesign), so I apologize in advance if this is an obvious question!
    SO, I often need to make documents (sign up sheets, donation forms, etc.) where I need to have something like this:
    Name: _____________________________
    Phone: _____________________________ (etc...)
    What is the best way to do this in InDesign without just putting in a line?!?!  Lines (as far as I can figure out) are not "fixed" (anchored?), so when I want to copy or move the text box or move down the "Name" title (or a lot of other things), the line does not move along with it and I have to spend a ridiculous amount of time making and re-making lines. There must be an easier way to do this, right?
    Thank you so much!!!

    I was on my way out the door when I posted earlier, so I didn't tell you as much as I could have.
    Absolutely make use of right-indent tabs where they work. I also often use a space or thin space between the text and the tab to provide a separation between the text and the line. I usually use a character style to add the underline, and you can either use find/change to apply it after you are done, or if you're ambitious you can use a nested style.
    If you want to use a nested style, start by applying none up to 1 ^t^y then the underline style through 1 ^t^y and finally repeat the last two styles. ^t is the metacharacter for a tab and ^y is the metacharacter for a right indent tab, and both are probably in the list of things you can select in the dialog, but now you know in case they aren't. One of the quirks of nested styles is that if you add more than one character to the trigger, ID will use the first one it finds from the list, so by adding BOTH types of tabs ID will find both a regular and right indent tab, or several regular tabs, on the same line, using the same nested style.

  • HT2523 how to make a simple line across the page

    how to mmake a line across

    In what application, running what version of OS X?
    (A Mac cannot run iOS)

  • How to make a dotted line starburst shape

    I am trying to make a starburst shape with dotted lines. I cannot seem to figure it out. Any ideas??

    Here are a few approaches:

  • How to make a new line (\n) in JList?

    Hi,
    How can I get an index[n] to span over several lines in JList? For example:
    ---[line 1]------------------------------------
    Thuesday: Dentist at 4 pm.
    ---[line 2]------------------------------------
    Friday: Carshop at 11 am.
    Dinner at 7 pm.
    ---[line n]------------------------------------
    etc. etc.
    I have tried with new live symbol (\n) and (\r) and even the linebreak symbol in hml (<br>) but it only writes out a square or <br>. Have you got any ideas??
    Best regards
    Tonni Aagesen

    JList use a CellRenderer (by default a JLabel) to paint cells in the list, this is why a '\n' is displayed like a square. If you want the cells to be painted in a different way, you have to provide your own CellRenderer. Take a look at the API:
    http://java.sun.com/j2se/1.3/docs/api/index.html
    and specially the section in the header that talks about CellRenderer.

  • CS1-Mac  How to make a graduated line (ruler) in ID?

    I'm a self-taught ID CS1 amateur.  I'm laying out a presentation in ID that will be projected page by page from a multi-page PDF file.  I need to make a diagram for one page that shows three separated, long vertical lines where each line is cross-hatched at precise intervals, such as a ruler that shows centimeters and millimeters where the centimeter has the longest cross-hatch and the millimeter the shortest except the 5th millimeter that has an intermediate-length cross-hatch.
    Each vertical line will have its own standard spaces separating the cross-hatches.  No line is expected to serve as a precise ruler, but uniform, designated spacing on each is highly desirable.
    I can find no tool in ID CS1 or Illustrator CS1 that enables me to accomplish this purpose.  Can someone either point it out to me or suggest a work-around?  If CS4 can do this, I will upgrade immediately.  Thanks in advance for any help you can give.
    Mac Pro 2.8GHz Quad-core Intel Xeon; 2 processors, 8 cores, 2GB RAM MacOS X 10.5.6, all security updates, Time Capsule 500GB, 3 internal hard drives (1 main drive, two internal backups); Apple Cinema HD Display 30" (2560x1600 res); ATI Radeon HD 2600 XT; 32-bit color.

    You can use a tall, dashed rule to get what you want.
    Use the line tool to draw a line and then format the stroke as shown. Play with it to get the look you want. If you want uneven bars, you can stack one line on top of the other and make the top one have fewer bars by spreading the dashes further apart.
    Ken Benson

  • How to make Mail break lines at X characters?

    Hi!
    Is there a way to have Mail automatically create linebreaks at a certain character length when composing an e-mail? It's a common request on many mailing lists to not send e-mails with longer lines than 80 characters.
    Please help!
    /roda

    A coworker has the same issue. When he sends to another colleague that uses the command line mail app in Linux, the Linux user only sees one long line for each paragraph.
    To (sort of) fix this in Snow Leopard, we created an Automator service that takes highlighted text, runs the Unix command line "fmt" command, and replaces the text with the wrapped text.
    To do the same, start Automator and select the Service template. The first line has:
    Service receives selected "text" in "any application"
    Leave the first item as "text" and either leave "any application" or change it to "Mail.app".
    Make sure Replaces selected text is highlighted.
    Next, click on the Utilities icon under Actions. Drag the "Run Shell Script" icon to the right pane. Replace "cat" with "fmt -s -70" to wrap lines at 70 characters and collapse whitespace (multiple spaces, tabs) into a single space. If you do not want to collapse the spaces, leave out the "-s". Use Save as to name the new service.
    Open System Preferences, select Keyboard and then Keyboard Shortcuts. Click on Services. Scroll down and find your new service. Click on the + at the bottom of the window. Select Application and choose Mail or all applications. Give it a name (I reused the same name as the service) and a shortcut.
    To use it, highlight the text and press the keyboard shortcut. The text should reappear wrapped at 70 characters. If you edit some more and the lines no longer wrap correctly, just run it again.
    Scott

  • How I make my menu line-up horizontally with my logo?

    I want to have my logo in the top left and my menu in the top right - horizontally even with one another. How I do this? Once I put the logo it seem not want anything else across from it

    Change this:
    <div class="header"><a href="#"></a><a href="#"></a><a href="#"></a><a href="#"></a><img src="Images/kurtlogo.fw.png" width="245" height="65" alt="logo" />
      <!-- end .header --></div>
      <div id="navigationbar"><nav><a href="index.html">Home</a> | <a href="about.html">About</a> | <a href="portfolio.html" class="navtext">Portfolio</a> | <a href="plogo.html">Logos</a> | <a href="contact.html" class="navtext">Contact</a></nav></div>
    to this:
    <div class="header">
    <div class="logo">
    <a href="#"></a><a href="#"></a><a href="#"></a><a href="#"></a><img width="245" height="65" alt="logo" src="Images/kurtlogo.fw.png">
    </div>
    <div id="navigationbar"><nav><a href="index.html">Home</a> | <a href="about.html">About</a> | <a class="navtext" href="portfolio.html">Portfolio</a> | <a href="plogo.html">Logos</a> | <a class="navtext" href="contact.html">Contact</a></nav></div>
    <!-- end .header --></div>
    Basically, we're putting the #navigationbar within header as well. We're then enclosing the logo within another div - so we can float the logo div left and navigationbar div right.
    Add this to your CSS:
    .logo{
    float: left;
    Find #navigationbar in your CSS:
    #navigationbar {
    background-color:#0FF;
    padding: 10px;
    float: right;
    Add the line in bold above (float).
    For footer, find this:
    .footer {
    padding: 10px;
    padding-left: 20px;
    padding-right: 20px;
    background-color: #0033ff;
    position: absolute;/* this gives IE6 hasLayout to properly clear */
    clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
    background-image: url(Images/background.jpg);
    width: 921px;
    height: 128px;
    top: 760px;
    Remove position line that I've struck out.
    Then, open portfoliomain.css file:
    .f11 {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 16px;
    color: #FC3;
    position: absolute;
    Remove the line I've struck out.

  • How to make some seperate lines as one paragraph in MS Word2013

    hi friends
    when i copy & paste a part of a book (for example a paragraph) from .pdf files into MSWord 2013, the paragraph is pasted as separate lines,so i have to manually edit that. it takes long time.
    i have pasted my problem in following pictures, but i don't now what setting to select to achieve may goal.
    any help please.
    thanks in advanced.
    it is before edit:
    now i don't know what to do in this page, so that space get removed, lines be attached together, so that they become one paragraph
    so that at the end, they become like this:
    " You can use the ImageX Windows AIK tool to create a WIM file that images a reference computer. Unlike ISO files, which are used to contain images of operating systems and toolkits across an intranet or the Internet, WIM is a file-based disk image
    format that contains a set of files and associated file system metadata .However, unlike sector-based formats (such as ISO) used for CD-ROM and DVD-ROM images, WIM is file-based, which means that the smallest unit of information in a WIM image is a file .A
    file-based image is hardware-independent and provides unique single-instance storage of a file that can be referenced multiple times in the file system tree"

    To prevent such a macro from being applied to the entire document, you can set the Wrap property of Selection.Find to wdFindStop. For example:
    Sub RemoveParagraphMarks()
    With Selection.Find
    .ClearFormatting
    .Text = "^p"
    .Replacement.ClearFormatting
    .Replacement.Text = " "
    .MatchWildcards = False
    .MatchWholeWord = False
    .Wrap = wdFindStop
    .Execute Replace:=wdReplaceAll
    End With
    End Sub
    Regards, Hans Vogelaar (http://www.eileenslounge.com)
    really thanks again Hans.
    i am now very interested in learning Macros in word.
    i am not familiar with macros & visual basic or programming.
    can you introduce me some reference to learn macro creation from base
    thanks in advanced  

Maybe you are looking for