How connect dragable labels with line

When I load the program labels will appear within the window. You can ckick
and drag these labels. The code for this
is very simple. The code works perfectly. However I want to extend my code to do
the following :
(1) I want to add an extra label .. it does not matter where on the screen
[ JLabel label = new JLabel() ]
(2) When I press this button I want a line to appear between the two
moveable labels ( ie the two labels are joined together by the line)
(3)Now here is the hard part.. Whenever I move either of the two labels
the line stretches so that the two labels are still connected.
start--->
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.border.*;
public class Connection
public static void main(String[] args)
JFrame f = new JFrame("Connection");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new ConnectionPanel());
f.setSize(400,300);
f.setLocation(200,200);
f.setVisible(true);
class ConnectionPanel extends JPanel
JLabel label1, label2, label3, label4;
JLabel[] labels;
JLabel selectedLabel;
int offsetX, offsetY;
boolean dragging;
public ConnectionPanel()
setOpaque(false);
setLayout(null);
addLabels();
addMouseListener(new LabelSelector());
addMouseMotionListener(new LabelMover());
public void paintComponent(Graphics g)
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.white);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setPaint(Color.blue);
Point
p1 = getCenter(label1),
p2 = getCenter(label2),
p3 = getCenter(label3),
p4 = getCenter(label4);
g2.draw(new Line2D.Double(p1.x, p1.y, p2.x, p2.y));
g2.draw(new Line2D.Double(p1.x, p1.y, p3.x, p3.y));
g2.draw(new Line2D.Double(p1.x, p1.y, p4.x, p4.y));
g2.draw(new Line2D.Double(p2.x, p2.y, p3.x, p3.y));
g2.draw(new Line2D.Double(p2.x, p2.y, p4.x, p4.y));
g2.draw(new Line2D.Double(p3.x, p3.y, p4.x, p4.y));
super.paintComponent(g);
private Point getCenter(JComponent c)
Rectangle r = c.getBounds();
return new Point((int)r.getCenterX(), (int)r.getCenterY());
private class LabelSelector extends MouseAdapter
public void mousePressed(MouseEvent e)
Point p = e.getPoint();
for(int i = 0; i < labels.length; i++)
Rectangle r = labels.getBounds();
if(r.contains(p))
selectedLabel = labels[i];
offsetX = p.x - r.x;
offsetY = p.y - r.y;
dragging = true;
break;
public void mouseReleased(MouseEvent e)
dragging = false;
private class LabelMover extends MouseMotionAdapter
public void mouseDragged(MouseEvent e)
if(dragging)
int x = e.getX() - offsetX;
int y = e.getY() - offsetY;
Rectangle r = selectedLabel.getBounds();
selectedLabel.setBounds(x, y, r.width, r.height);
repaint();
private void addLabels()
int w = 125;
int h = 25;
Border border = BorderFactory.createEtchedBorder();
label1 = new JLabel("Label 1", JLabel.CENTER);
label2 = new JLabel("Label 2", JLabel.CENTER);
label3 = new JLabel("Label 3", JLabel.CENTER);
label4 = new JLabel("Label 4", JLabel.CENTER);
labels = new JLabel[4];
labels[0] = label1; labels[1] = label2; labels[2] = label3; labels
[3] = label4;
for(int i = 0; i < labels.length; i++)
labels[i].setBorder(border);
labels[i].setOpaque(true);
labels[i].setBackground(Color.white);
add(labels[i]);
label1.setBounds(40, 40, w, h);
label2.setBounds(215, 40, w, h);
label3.setBounds(40, 200, w, h);
label4.setBounds(215, 200, w, h);
end-->
In this code: How to add labels when to me it is necessary
(From menu: add new label)?

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class Connection
    ConnectionPanel connectionPanel;
    LabelWrangler wrangler;
    public Connection()
        connectionPanel = new ConnectionPanel();
        wrangler = new LabelWrangler(connectionPanel);
        connectionPanel.addMouseListener(wrangler);
        connectionPanel.addMouseMotionListener(wrangler);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(getUIPanel(), "North");
        f.getContentPane().add(connectionPanel);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
    private JPanel getUIPanel()
        JButton add = new JButton("add label");
        add.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                wrangler.willAcceptLabel = true;
        JCheckBox lineBox = new JCheckBox("show lines");
        lineBox.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                connectionPanel.showConnectionLines();
        JPanel panel = new JPanel();
        panel.add(add);
        panel.add(lineBox);
        return panel;
    public static void main(String[] args)
        new Connection();
class ConnectionPanel extends JPanel
    boolean showConnections;
    int labelCount;
    final int
        N  = 2,
        NW = 3,
        W  = 1,
        SW = 9,
        S  = 8,
        SE = 12,
        E  = 4,
        NE = 6;
    public ConnectionPanel()
        showConnections = false;
        labelCount = 0;
        setLayout(null);
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        if(showConnections)
            Component[] c = getComponents();
            Rectangle r1 = new Rectangle();
            Rectangle r2 = new Rectangle();
            for(int j = 0; j < c.length - 1; j++)
                c[j].getBounds(r1);
                for(int k = j + 1; k < c.length; k++)
                    c[k].getBounds(r2);
                    Point p1 = getClosestPoint(r1, r2);
                    Point p2 = getClosestPoint(r2, r1);
                    g2.draw(new Line2D.Double(p1.x, p1.y, p2.x, p2.y));
    private Point getClosestPoint(Rectangle r1, Rectangle r2)
        double cx = r2.getCenterX();
        double cy = r2.getCenterY();
        Point p = new Point();
        int outcode = r1.outcode(cx, cy);
        switch(outcode)
            case N:
                p.x = r1.x + r1.width/2 - 1;
                p.y = r1.y;
                break;
            case NW:
                p.x = r1.x;
                p.y = r1.y;
                break;
            case W:
                p.x = r1.x;
                p.y = r1.y + r1.height/2 - 1;
                break;
            case SW:
                p.x = r1.x;
                p.y = r1.y + r1.height - 1;
                break;
            case S:
                p.x = r1.x + r1.width/2 - 1;
                p.y = r1.y + r1.height - 1;
                break;
            case SE:
                p.x = r1.x + r1.width - 1;
                p.y = r1.y + r1.height - 1;
                break;
            case E:
                p.x = r1.x + r1.width - 1;
                p.y = r1.y + r1.height/2 - 1;
                break;
            case NE:
                p.x = r1.x + r1.width - 1;
                p.y = r1.y;
                break;
            default /* INSIDE == 0 */:
                System.out.println("INSIDE");
        return p;
    public void addLabel(Point p)
        JLabel label = new JLabel("label " + ++labelCount);
        label.setBorder(BorderFactory.createEtchedBorder());
        add(label);
        Dimension d = label.getPreferredSize();
        label.setBounds(p.x - d.width/2, p.y - d.height/2, d.width, d.height);
        repaint();
    public void showConnectionLines()
        showConnections = !showConnections;
        repaint();
class LabelWrangler extends MouseInputAdapter
    ConnectionPanel connectionPanel;
    Component selectedLabel;
    Point offset;
    boolean dragging, willAcceptLabel;
    public LabelWrangler(ConnectionPanel cp)
        connectionPanel = cp;
        offset = new Point();
        willAcceptLabel = false;
        dragging = false;
    public void mousePressed(MouseEvent e)
        Point p = e.getPoint();
        // has a label been selected for dragging?
        Component[] c = connectionPanel.getComponents();
        Rectangle r = new Rectangle();
        for(int j = 0; j < c.length; j++)
            c[j].getBounds(r);
            if(r.contains(p))
                selectedLabel = c[j];
                offset.x = p.x - r.x;
                offset.y = p.y - r.y;
                dragging = true;
                break;
        // if no selection, are we adding a new label?
        if(!dragging && willAcceptLabel)
            connectionPanel.addLabel(p);
            willAcceptLabel = false;
    public void mouseReleased(MouseEvent e)
        dragging = false;
    public void mouseDragged(MouseEvent e)
        if(dragging)
            int x = e.getX() - offset.x;
            int y = e.getY() - offset.y;
            selectedLabel.setLocation(x, y);
            connectionPanel.repaint();
}

Similar Messages

  • PPR Report ,How to display Label with TOTAl

    Hi,
    How Can i display PPR Report ,How to display Label with TOTAl like
    [http://apex.oracle.com/pls/apex/f?p=267:30:]
    Thanks
    Edited by: 805629 on Jan 6, 2011 3:34 AM

    Hi,
    For PPR Report:
    Select "Yes" in "Enable Partial Page Refresh" item of "Layout and Pagination" region in Report Attributes of that report.
    For display Label with TOTAL:
    Use "Break Formatting" region in Report Attributes of that report.
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • Drag and Drop Labels with line interconnected

    Dear all,
    As before, I use java.awt.dnd objects and java.awt.datatransfer objects to help me to drag and drop some labels with right-click my mouse.
    Now I would like to left-click my mouse to draw a line between the two labels by pressing the left-click on label 1 and drag and drop to label 2. Then I would like to see a now line created betwwen label 1 and 2. I have an idea to addMouseListener and addMouseMotionListener on the labels to get the position of the labels and draw a line with the position. But I found that both right-click and left-click can trigger this event. Can I give some restriction on that so only left-click can trigger this event.
    Also I cannot do it successfully as I found that after I rewrite the paintComponent method, the older image cannot be cleared and make the screen become verbose. Do I missing something on rewrite the paintComponent method? Also do you have any other suggestion on the task of drawing a line between the 2 labels?
    Thanks a lot!
    Peter

    Of course you can select only left click events :
    You simply add a test like that in your Mouse(Motion)Listener's methods :
    if (SwingUtilities.isLeftMouseButton(aMouseEvent)) {
    I hope this helps,
    Denis

  • How to fill canvas with lines

    <mx:Canvas id="b1" x="10" y="10" height="40" width="300" borderStyle="solid" borderColor="black"/>
    when i want to draw lines with 15 pixels gap to fill the entire canvas i wrote as follows
                   for(var i:int=b1.x+15;i<b1.x+b1.width;i=i+15)
                        var line1:UIComponent = new UIComponent();
                        var lineThickness1:Number = 1;
                        var lineColor1:Number = 0x000000;
                        var lineAlpha1:Number = 1;
                        line1.graphics.lineStyle(lineThickness1,lineColor1,lineAlpha1);
                        line1.graphics.moveTo(i,b1.y);
                        line1.graphics.lineTo(i,b1.y+b1.height);
                        this.addChild(line1);
    it's working fine
    lly,
    <mx:Canvas id="b4" x="600" y="200" height="60" width="300" borderStyle="solid" borderColor="black" rotation="40"/>
    I have the above canvas with id 'b4' only difference is that this canvas has the rotation
    how to fill this canvas with lines just i did above?

    Hope this code will help you,
    for(var i: int = 15; i < b4.width; i = i + 15) {
         var line1: UIComponent = new UIComponent();
         var lineThickness1: Number = 1;
         var lineColor1: Number = 0x000000;
         var lineAlpha1: Number = 1;
         line1.graphics.lineStyle(lineThickness1, lineColor1, lineAlpha1);
         line1.graphics.moveTo(i, 0);
         line1.graphics.lineTo(i, b4.height - 1);
         //Add line in canvas instead of main container
         b4.addChild(line1);
    <mx:Canvas id="b4" x="600" y="200" height="60" width="300" borderStyle="solid" borderColor="black" rotation="40"/>

  • How to use label with break

    I'd like to learn how to use label, but why the following code didn't work?
    public class Try {
    public static void main(String[] args) {
    aLabel:
    System.out.println("A");
    for(int i=1; i<=2; i++) {
    if(true) {
    break aLabel;
    System.out.println("B");
    Thanks,

    You can label simple blocks as well, and exit the blocks with break.
    This code compiles and runs successfully.
    public class Try {
        public static void main(String[] args) {
            aLabel: {
                System.out.println("A");
                for(int i=1; i<=2; i++) {
                    if(true) {
                        break aLabel;
            System.out.println("B");
    }

  • How to send string with line feed to Agilent 33250A via COM1

    Agilent 33250A is a function generator. In HPERTERMINAL, when "Send line ends with line feeds" is enabled, simple strings make it work well, such as: "APPLQU", "OUTPUT ON", etc...
    But I can't make it work with .vi file. COM setting is correct because 33250A shows "remote" icon immediatly after string sent. It will respon "error" to any mismatched setting (e.g. 9600 vs 115200). So, the connection is there but it just doesn't respond to commands.
    I don't know why. The termination character is enabled in .vi
    I apprecite your help to make the .vi to send string just like the HYPERTERMINAL with 'line feeds'.
    Thank you very much.
    Jian
    Attachments:
    Serial_Communication.vi ‏40 KB
    Write2COM1.vi ‏22 KB

    From what I can see it looks like you are NOT specifying what termination character you want to use when you call the serial port init.
    When not otherwise specified, the port will be configured to use the default termination character which is a "carrige return" HEX 0A.
    Try wiring a "Line Feed" constant to the init VI.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to link label with an input field in data table?

    I am curious if there is a nice way to link a label to input field in a data table directly in JSP? Data filling the table are dynamically bounded.
    Sample, simplified code below. Values of "label" property are unique in the collection binded to dataTable.
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:jsp="http://java.sun.com/JSP/Page">
         <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" />
         <f:view>
              <html>
              <body>
              <h:dataTable value="#{screen$monitoring$errorlog$CorrectHopper.dataset}" var="DATA_ROW">
                   <h:column>
                        <f:facet name="header">
                             <h:outputText value="Name" />
                        </f:facet>
                        <h:outputLabel value="#{DATA_ROW.label}" for="#{DATA_ROW.label}_id" />
                   </h:column>
                   <h:column>
                        <f:facet name="header">
                             <h:outputText value="Value" />
                        </f:facet>
                        <h:inputText value="#{DATA_ROW.label}" id="#{DATA_ROW.label}_id" />
                   </h:column>
              </h:dataTable>
              </body>
              </html>
         </f:view>
    </jsp:root>
    returns:
    17:39:01,390 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
    java.lang.IllegalArgumentException: #{DATA_ROW.label}_id
    what is related to EL expression in h:inputText's "id" attribute.
    Is there any other way to bind label with dynamically created input field in JSP? Do I really have to bind input field directly to component objects with "binding" and set IDs manually with setId() (what is ugly solution because it moves View related logic to Model layer)?

    I've thought of using EL because I have to somehow
    link a label to an input field dynamically. Somehow? Dynamically? Just use plain text :)Well... just look at my code snippet (notice: we want to join the pairs of labels and text boxes placed in a datatable [or any other repeater-like component rendering properties of objects from a collection]):
    <h:dataTable value="#{screen$monitoring$errorlog$CorrectHopper.dataset}" var="DATA_ROW">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name" />
    </f:facet>
    <h:outputLabel value="#{DATA_ROW.label}" for="#{DATA_ROW.label}_id" />
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Value" />
    </f:facet>
    <h:inputText value="#{DATA_ROW.label}" id="#{DATA_ROW.label}_id" />
    </h:column>
    </h:dataTable>
    and what is your idea of using plain text as "id" attribute value in this case? :)
    Regards,
    Michal

  • How to connect two JComponents with line

    Hi,
    I have GUI which draws different shapes(ovals, rectangles etc) as JComponants on a JPanel . I need to be able to select by clicking a JComponant and connect it to another JComponant on the JPanel. Once I haved established a connection I would like to be able to move the connected JComponants yet maintain the connection. Can you please look at my code and advise as to how this can be achieved.
    Thanks.
    LineSelector selector = new LineSelector(windowPanel);
    windowPanel.addMouseListener(selector);
    class windowPanel extends JPanel
    ArrayList lines;
    public windowPanel()
    lines = new ArrayList();
    protected void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setColor(Color.white);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    for(int j = 0; j < lines.size(); j++)
    g2.draw((Line2D) lines.get(j));
    protected void addConnectingLine(Component c1, Component c2)
    Rectangle r1 = c1.getBounds();
    Rectangle r2 = c2.getBounds();
    lines.add(new Line2D.Double(r1.getCenterX(), r1.getCenterY(),
    r2.getCenterX(), r2.getCenterY()));
    repaint();
    class LineSelector extends MouseAdapter
    windowPanel conPanel;
    Component firstSelection;
    boolean firstComponentSelected;
    public LineSelector(windowPanel cp)
    conPanel = cp;
    public void mousePressed(MouseEvent e)
    Point p = e.getPoint();
    Component[] c = conPanel.getComponents();
    Rectangle rv = new Rectangle();
    for(int j = 0; j < c.length; j++)
    c[j].getBounds(rv);
    if(rv.contains(p))
    if(firstComponentSelected)
    conPanel.addConnectingLine(c[j], firstSelection);
    firstComponentSelected = false;
    else
    firstSelection = c[j];
    firstComponentSelected = true;
    break;
    }

    Hi,
    these threads can help you
    http://forum.java.sun.com/thread.jspa?threadID=488823&messageID=2292924
    http://forum.java.sun.com/thread.jspa?forumID=20&threadID=607264
    L.P.

  • How to Axis labels for Line charts in Business Graphics

    Hi
    I am planning to do the Business Graphic example using Line chart.As part of this
    i didn't clearly understand what is the perpose of Series,Points,categorys?
    if i want to set the Labels at X-axis and y axis ,then how to do that?Baiscally i want to put time related data as X-axis label(20min,30min,60 min etc).Please help.
    is there any good example to understand the concept?
    Thanks
    Prasad

    Hi Bachier
    Thanks for your repsonce.I had seen the example you suggested.but there is no answer for my question.How to set the x-Axis,Y-axis Labels.I had done example for "line chart".But i have same problem:
    Hi
    I am trying to do example on "line chart" using Business graphics in my webdynpro application.
    In the Context i created Node "A" under which i created "B".then it has  value attributes xValue,yValue.Then in View i created BG UI element >Series>point-->NumericValue(for xValue) ,NumericaValue(yValue).Now in view init() method i had initialized values to x and y. some output is coming.but i want to know how to set the X-Axis Label,y-Axis Labels.in X-Aix Label i want to mention time in hrs i.e 8.00,8.30AM,9.00AM,9.30AM etc.as part of y-axis labels i want to mention numeric values( .2,.4,.8,2.0 etc). Please tell me how to set this X-Axis,y-Axis labels.at every 30min(8.00Am,8.30AM etc) user enter quality data(i.e .2 etc) then i want to generate chart.Please help in this regard.i will give very good points
    Thanks
    Prasad

  • How connect to hsdpa   with iphone 5

    I need help. Last Week I Bought a new iPhone 5 Unlocked in Istore Miami. I'm setting APN Carrier  like in my old iPhone 4. I'm expecting to catch , browsing with HSDPA+ red ( like we named GSM 4G), but NOT, ONLY 3G !  Why ? Iphone 5 can connect to HSDPA ! . I live in Lima PERU, my carrier is  CLARO PERU. Here we have good covered to HSDPA+ red . I setting my iphone in General/celular where to set ask me only : APN Carrier : claro.pe, Name User: claro and Password: claro, nothing more. I must introduce more information ? and if yes where and how ? thank you for yours answers.

    The only iPhone that will display a "4G" logo when connected to an HSPA+ network is one originally sold for use on AT&T. It's a marketing thing, not a technical issue.

  • How to create Labels with continuous numbering?

    I would like to create a page of labels, each label has a number in it, and must be incrememnted by one, so a page might have labels numbered 29 through 38 (10 labels per page). I would like to set the page up so that I only need to enter the first label number, and the rest of the labels adjust accordingly. Is this possible?
    Thanks!
    ~Mike

    You can do this with a work around.
    See Numbered Tickets:
    http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=182&mforum=iworktips ntrick
    Alternatively you can use a Table. Pages will sequence numbers in a table if you enter any kind of a sequence(including dates, days, months etc), in two successive cells, select both and drag out the bottom right white dot to folowing cells.
    Peter

  • How connect Nokia 6230i with bluetooth GPS

    I have:
    [a] Nokia 6230i (BT 1.1, ver phone firm. "v 03.88")
    [b] GPS bluetooth path modul HI-406BT (BT 1.1)
    All device [a,b] connect to notebook, PDA (PcSuite, etc.)
    In phone founder BT device neighbor not found GPS.
    If use special soft for navigation (as TrekBuddy), device is found, but not connected.
    I mean, that [b] will connect via pass-phrase. Or..., know anybody where is problem?

    Hi kapral37
    Only ever remember using Nav4All software on 6230i which found Nokia LD-3W when application looked for it so can't help you here unfortunately. 
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • How connect my iPad with Facebook, how connect my iPad with Facebook

    how can I make my Facebook say via iPad 2

    Download the Facebook app
    http://itunes.apple.com/sg/app/facebook/id284882215?mt=8&ls=1

  • Connect specified words in textframe with lines

    Dear all,
    I want to use the script below and change it to a script that connects specified words with lines. Now it connects all the words with lines. I'm not sure what to do, so I hope someone can help me.
    Thanks in advance
    #include ./lib/bene.jsx
    //InDesign CS2 JavaScript
    //Set to 4.0 scripting object model
    app.scriptPreferences.version = 4.0;
    var myScriptName = app.activeScript.name;
    var myObjectList = new Array;
    if (app.documents.length != 0){
         if (app.selection.length != 0){
             for(var myCounter = 0;myCounter < app.selection.length; myCounter++){
                 switch (app.selection[myCounter].constructor.name){
                     //allow only textframes
                     case "TextFrame":
                         myObjectList.push(app.selection[myCounter]);
                         break;
             if (myObjectList.length != 0){
                 //run the thing! call a function           
                 myConnectWords(myObjectList);
             else{
                 alert ("Please select TextFrame and try again.");
         else{
             alert ("Please select an object and try again.");
    else{
         alert ("Please open a document, select an object, and try again.");
    //functions
    function myConnectWords(myObjectList){
         var myDocument = app.activeDocument;
         var myLayer, myCounter, myColor;
         //Measurement
         var myOldRulerOrigin = myDocument.viewPreferences.rulerOrigin;
         myDocument.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;
         //Save the current measurement units.
         var myOldXUnits = myDocument.viewPreferences.horizontalMeasurementUnits;
         var myOldYUnits = myDocument.viewPreferences.verticalMeasurementUnits;
         //Set the measurement units to points.
         myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
         myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
         //Get references  the None swatch.       
         var myNoneSwatch = myDocument.swatches.item("None");   
         //Create a color (if it does not already exist).   
         myColor = myDocument.colors.item(myScriptName);
         try{
             myColorName = myColor.name;
         catch (myError){
             var myColorArray = new Array(100, 0, 0, 0);
             myColor = myDocument.colors.add({model:ColorModel.process,  space: ColorSpace.CMYK, colorValue:myColorArray,name: myScriptName});        
         //Create a layer to hold the generated lines (if it does not already exist).
         myLayer = myDocument.layers.item(myScriptName);
         try{
             myLayerName = myLayer.name;
         catch (myError){
             myLayer = myDocument.layers.add({name:myScriptName});
         //Process the objects (here text frames) in the selection.   
         for(myCounter = 0; myCounter < myObjectList.length; myCounter ++){
             //get textframe
             var myNewFrame = myObjectList[myCounter];       
             //get all lines in the frame
             var myLines = myNewFrame.lines;
             //connect each word with all words in the next line
             for(myLineCounter = 0; myLineCounter < myLines.length-1; myLineCounter ++){
                 //get all words in the line + next line
                 var myLine = myLines[myLineCounter].words;           
                 var myNextLine = myLines[myLineCounter+1].words;           
                 //myPathPoints.push([myLine.insertionPoints[-2].horizontalOffset,myTmpY]);
                //combine this + next line words
                 for(i = 0; i < myLine.length; i++){   
                     //get word       
                     var myWord_i = myLine[i];
                     //array for points
                     var myPathPoints = new Array;
                     //add fist point X/Y               
                     myPathPoints[0]=[myWord_i.horizontalOffset,myWord_i.baseline]; 
                    for(j = 0; j < myNextLine.length; j++){
                        //get word
                        var myWord_j = myNextLine[j];                                     
                        if (myWord_j.baseline != myWord_i.baseline  && myWord_j.horizontalOffset != myWord_i.horizontalOffset) {
                            //add secound point X/Y
                            myPathPoints[1]=[myWord_j.horizontalOffset,myWord_j.baseline];
                            //draw the line
                            myDrawPolygon(myPathPoints, 1, 100, myColor, myNoneSwatch, myLayer);          
        myDocument.viewPreferences.rulerOrigin = myOldRulerOrigin; 
        //Set the measurement units back to their original state. 
        myDocument.viewPreferences.horizontalMeasurementUnits = myOldXUnits; 
        myDocument.viewPreferences.verticalMeasurementUnits = myOldYUnits; 

    Yup -- Fun little exercise, this was.
    Select either an entire text frame, or some text directly, and this script connects all of the words with the character style "label". The lines are at the baseline center of each word.
    if (app.documents.length == 0 || app.selection.length != 1 ||
    !(app.selection[0] instanceof TextFrame || app.selection[0].hasOwnProperty("baseline")))
    alert ("Please select a single text frame or some text first");
    } else
    charStyleName = "label";
    app.findTextPreferences = null;
    app.findTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item(charStyleName);
    list = app.selection[0].findText();
    if (list.length == 0)
      alert ('No text found with char style "'+charStyleName+'"');
    else if (list.length == 1)
      alert ('Only one text found with char style "'+charStyleName+'", no use in going on');
    else
      lpath = [];
      while (list.length)
       lpath.push ( centerOfWord (list.shift()) );
      if (app.selection[0] instanceof TextFrame)
       pg = app.selection[0].parent;
      else
       pg = app.selection[0].parentTextFrames[0];
      while (!(pg instanceof Spread || pg instanceof MasterSpread || pg instanceof Page))
       if (pg instanceof Document || pg instanceof Application)
        break;
       pg = pg.parent;
      l = pg.graphicLines.add({strokeWeight:0.5, strokeColor:app.activeDocument.swatches.item("Black")});
      l.paths[0].entirePath = lpath;
    function centerOfWord (word)
    var l = word.insertionPoints[0].horizontalOffset;
    var r = word.insertionPoints[-1].horizontalOffset;
    return [ (l+r)/2, word.baseline ];

  • To print labels with barcodes in sap-scripts

    how to print labels with barcodes in sap-scripts . explain with example.

    Hi,
    What was wrong with the answers you were given the first time you asked this question?
    labels with barcodes in smart forms
    Why have you ignored their efforts and logged the same question again?
    Nick

Maybe you are looking for