Ruler with line numbering and cury text underline

Hi,
I've just started programming in java and as an exercise i was trying to make an simple text editor. Uptil now i've been able to make a textarea and a menu with items and such, but i have 2 things that i'm very curious about.
1. How can I make a vertical ruler with line numbers in it? (like in JBuilder/Eclipse editors) I'm planning on putting it next to the text so I can see at which line in the document i'm at.
2. How can I underline (mark) text with those curly lines you often see in applications? (i.e. Marking grammar and spelling errors in MS Word or marking programming errors in editors like JBuilder/Eclipse)
I hope that these things can be done in Java. If someone could help me out with this, i'd be very grateful.
Kayhne

Try this.
regards,
Stas
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.util.*;
class Test {
    public Test() {
        JFrame fr = new JFrame("TEST");
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JEditorPane pane = new JEditorPane();
        pane.setEditorKit(new NewEditorKit());
        pane.setText("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test ");
        StyledDocument doc = (StyledDocument) pane.getDocument();
        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setLineSpacing(attr, 5f);
        doc.setParagraphAttributes(0, doc.getLength(), attr, false);
        JScrollPane sp = new JScrollPane(pane);
        fr.getContentPane().add(sp);
        fr.setSize(300, 300);
        fr.show();
    public static void main(String[] args) {
        Test test = new Test();
class NewEditorKit extends StyledEditorKit {
    public ViewFactory getViewFactory() {
        return new NewViewFactory();
class NewViewFactory implements ViewFactory {
    public View create(Element elem) {
        String kind = elem.getName();
        if (kind != null) {
            if (kind.equals(AbstractDocument.ContentElementName)) {
                return new JaggedLabelView(elem);
            else if (kind.equals(AbstractDocument.ParagraphElementName)) {
                return new ParagraphView(elem);
            else if (kind.equals(AbstractDocument.SectionElementName)) {
                return new BoxView(elem, View.Y_AXIS);
            else if (kind.equals(StyleConstants.ComponentElementName)) {
                return new ComponentView(elem);
            else if (kind.equals(StyleConstants.IconElementName)) {
                return new IconView(elem);
        // default to text display
        return new LabelView(elem);
class JaggedLabelView extends LabelView {
    public JaggedLabelView(Element elem) {
        super(elem);
    public void paint(Graphics g, Shape allocation) {
        super.paint(g, allocation);
        paintJaggedLine(g, allocation);
    public void paintJaggedLine(Graphics g, Shape a) {
        int y = (int) (a.getBounds().getY() + a.getBounds().getHeight());
        int x1 = (int) a.getBounds().getX();
        int x2 = (int) (a.getBounds().getX() + a.getBounds().getWidth());
        Color old = g.getColor();
        g.setColor(Color.red);
        for (int i = x1; i <= x2; i += 6) {
            g.drawArc(i + 3, y - 3, 3, 3, 0, 180);
            g.drawArc(i + 6, y - 3, 3, 3, 180, 181);
        g.setColor(old);
}

Similar Messages

  • I am facing problem regarding graphical user interface. I am using text box for editing files. I want to show the line numbers and graphical breakpoint​s along with text box. Can anybody help me in this? Thanks.

    I am facing problem regarding graphical user interface. I am using text box for editing files. I want to show the line numbers and graphical breakpoints along with text box. Can anybody help me in this? Thanks.

    Thanks for you reply.
    But actually I don't want to show the \ (backslashes) to the user in my text box. 
    Ok let me elaborate this problem little more. 
    I want to show my text box as it is in normal editors e.g. In Matlab editor. There is a text box and on left side the gray bar shows the line numbers corresponding to the text. Further more i want that the user should be able to click on any line number to mark specific line as breakpoint (red circle or any graphical indication for mark). 
    Regards,
    Waqas Ahmad

  • Listing with line numbers

    how do I get a listing with line numbers to check compile errors with?

    how do I get a listing with line numbers to check compile errors with? What listing from where using what?
    AFAIK javac and jikes compilers give you the line numbers. What compiler are you using?
    Or do you mean how to display line numbers with this or that editor? If it isn't obvious I'd suggest getting a proper editor (as others have suggested)!
    BTW: eEdit = jEdit?

  • I have 1 apple id, 2 5S iPhones with separates numbers and both ring when I get a call on one of the numbers. How do I switch that of ?

    I have 1 Apple ID, 2 5S iPhones (1 private/1 work) with separates numbers and both phones ring when I get a call on one of the numbers. How do I switch that of ?

    I realize that my wife could make her own iTunes account; however, she's been using mine for about 2 years now and this hasn't been an issue.  I guess with the Family Sharing she can have access to all of our music and apps now with her own account. 
    I'll have to see if unchecking our emails resolves this issue.

  • HT4528 Can I put the same information on two different i-phones with different numbers and different ID's?

    Can I put the same information on two different i-phones with different numbers and different ID's?

    Yes and no it really depends on what information you are putting on the devices.

  • I was in a conversation with a colleague and a text (identical) came to both of our phones, when he researched it, it said it was blocked and I thought I might see where it came from through my phone. Is it possible to get a spam like that to our phones

    I was in a conversation with a colleague and a text (identical) came to both of our phones, when he researched it, it said it was blocked and I thought I might see where it came from through my phone. Is it possible to get a spam like that to our phones at the same time.If the text came to my number marked from him, it could only have been from him?. Is there a possibility that someone else sent it to both of us at the same time?

    Yes, it could be spam. I get spam text from time to time. Yes, you both could have gotten the same spam at the same time. Spammers re sending out thousands and thousands of messages.

  • How to change pdf (with dark background) so it print with white background and dark text??

    I have lots of nice presentations I am studying- the problem is most of them were made in ppt with dark backgrounds and white text then converted to pdf files. So when I print them, I get a dark (black) background with white text- very annoying. Is there anyway to get it to print with a light (or no) backround with black text? This is much easier for note taking/etc. I have adobe acrobat professional.

    Use the rectangle shape tool. Draw a rectangle over the entire frame. In the shape tab, color it whatever you want. Export your TGA sequence.
    Andy
    PS: But if you place a colored bkg in your motion project that you will effectively have no alpha channel. Are they referencing the TGA's alpha?

  • PDFs printing with black background and white text.

    For some reason some of our PDF's have been printing with black backgrounds and white text, even though they appear to be normal on the screen before they are printed. I haven't been able to confirm 100% yet but it appears to only be happening with pdfs that were created from scanned documents.
    Can somebody please offer me some suggestions.

    Absolutely agree with the original poster.  I find white text on black background so very very difficult (I changed from using Tweetbot on iOS to Tweetlogix for this very reason) and it physically hurts my eyes to try to read it.  I can just about manage with Spotify using white text on a black background on the large screen of my MacBook Pro - and I do mean "just" - but for the smaller screen of my iPhone 5 it is just impossible.  Even with a retina screen such as that on the iPhone 5S there is a strange ghosting effect and it gives me a headache to look at it for too long. 
    This may be something to do with age!  I suspect most app developers are youngsters with almost perfect eyesight, but for those of us whose eyesight is less than perfect, this white text on black background really is so very difficult.
    I know there is a workaround in setting the iPhone to invert ALL colours (under Accessibility in Settings) but it's a real pain to have to keep altering this setting every time I want to open or close Spotify, and it doesn't look right anyway.  iOS7 is supposed to be a light, bright, easy to read OS - sadly this new Spotify app is the opposite of that.
    Please would Spotify consider adding a simple light or dark theme option, so that those of us who want it can have our much easier to read light background back again, with grey or black text?  It would be a great help to those of us who have eyesight problems.
    If not, I may have to cancel my Spotify Premium account and move to Deezer instead, as I mainly use Spotify when out and about in the car, so am using the iOS app a lot.
    Thank you for considering this plea!
     

  • Best Architecture for Fortran Code with Line Numbers

    Hi all,
    I have large fortran 90 file (10+ pages) which I need to convert to LabVIEW.
    It contains several branching statements with Line Numbers, e.g.:
    1000 IF (condition) goto 2000
    I would like to know what is the best architecture to deal with this branching of the program.
    Should I break the sections (based on line numbers) into user events or states?
    Has anyone done similar conversions? 
    Cheers,
    Battler.

    battler. wrote:
    Hi all,
    I have large fortran 90 file (10+ pages) which I need to convert to LabVIEW.
    It contains several branching statements with Line Numbers, e.g.:
    1000 IF (condition) goto 2000
    I would like to know what is the best architecture to deal with this branching of the program.
    Should I break the sections (based on line numbers) into user events or states?
    Has anyone done similar conversions? 
    Cheers,
    Battler.
    I would insert a preliminary step where I would assign a descriptive name to each line number that is the target of a branch. The names become the names of the states (like Christian was hinting at) then diagram the code into a state transition diagram. The rest gets passed to a developer to complete.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to display polygons both with line contour and filled interior?

    How to display polygons both with line contour and filled interior?
    Java3D 1.3, Java 1.4.1-rc

    Hi,
    I just started with Java3D last week.
    I assume you mean drawing polygons with outlines (wireframe) in one color and polygon face filling with another color. If so, I've got the same question! (I usually think of "contour" to refers to plotting surface intensity of independent data like temperature or elevation, but I don't think you mean this.)
    The only solution I've found so far is to make two shapes with the same geometry.
    Here's an example - an outlined and filled cube. I made it using a generalize class DualShape which is two shapes with the same geometry, but one filled and one as a line.
    It works, although I can't say I understand the setPolygonOffset(), knowing what value to set. Without the command, the depthbuffer can't consistently decide which should be in front between the fills and lines so it looks bad.
    I certainly think it would be nicer to do both internally, like:
    pa.setPolygonMode(pa.POLYGON_LINE || pa.POLYGON_FILL);
    And then have setFillColor and setLineColor for each.
    I don't know why they don't allow this - maybe OpenGL can't do it like this so Java3D follows.
    If anyone has any better ideas I'd like to hear about it.
    Tom Ruen
    class DualCube extends DualShape // cube with outline and fill colors
    public DualCube(float ax, float ay, float az, //cube lower corner
    float bx, float by, float bz, //cube upper corner
    float br, float bg, float bb, //border color
    float fr, float fg, float fb) //fill color
    setGeometry(new CubeGeometry(ax,ay,az,bx,by,bz),br,bg,bb,fr,fg,fb);
    class DualShape extends BranchGroup //general shape with outline and fill colors
    Appearance ap1,ap2;
    PolygonAttributes pa1,pa2;
    ColoringAttributes ca1,ca2;
    Shape3D s1,s2;
    public void setGeometry(Geometry geo, float br, float bg, float bb, float fr, float fg, float fb)
    //filled shape:
    addChild(s1=new Shape3D(geo, ap1=new Appearance()));
    ap1.setPolygonAttributes(pa1=new PolygonAttributes()); pa1.setPolygonMode(pa1.POLYGON_FILL);
    ap1.setColoringAttributes(ca1=new ColoringAttributes()); ca1.setColor(fr,fg,fb);
    //lined (wire) shape:
    addChild(s2=new Shape3D(geo, ap2=new Appearance()));
    ap2.setPolygonAttributes(pa2=new PolygonAttributes()); pa2.setPolygonMode(pa2.POLYGON_LINE);
    ap2.setColoringAttributes(ca2=new ColoringAttributes()); ca2.setColor(br,bg,bb);
    pa2.setPolygonOffset(-1000); //Uncertain what "float" value to use!
    class CubeGeometry extends IndexedQuadArray //cube geometry data
    private static final int[] faces =
    0,3,2,1,
    0,1,5,4,
    1,2,6,5,
    2,3,7,6,
    3,0,4,7,
    4,5,6,7
    private static float[] verts = new float[24];
    public CubeGeometry(float ax, float ay, float az, //lower limit
    float bx, float by, float bz) //upper limit
    super(8, IndexedQuadArray.COORDINATES , 24);
    int n;
    n=0; verts[n]=ax; verts[n+1]=ay; verts[n+2]=az;
    n=3; verts[n]=bx; verts[n+1]=ay; verts[n+2]=az;
    n=6; verts[n]=bx; verts[n+1]=by; verts[n+2]=az;
    n=9; verts[n]=ax; verts[n+1]=by; verts[n+2]=az;
    n=12; verts[n]=ax; verts[n+1]=ay; verts[n+2]=bz;
    n=15; verts[n]=bx; verts[n+1]=ay; verts[n+2]=bz;
    n=18; verts[n]=bx; verts[n+1]=by; verts[n+2]=bz;
    n=21; verts[n]=ax; verts[n+1]=by; verts[n+2]=bz;
    setCoordinates(0, verts);
    setCoordinateIndices(0, faces);

  • Want to create a user field with type alphanmumeric and structure text through coding

    i want to create a user field with type alphanumeric and structure text through coding.am using vb
    plz help me

    Hi.
    Please take a look at samples in SAP B1 SDK.
    Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
    oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
    ' Adding "Name" field
    '// Setting the Field's properties
    oUserFieldsMD.TableName = #YOUR_TABLE_NAME#
    oUserFieldsMD.Name = "Name"
    oUserFieldsMD.Description = "Name"
    oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
    oUserFieldsMD.EditSize = #LENGTH_OF_FIELD#
    '// Adding the Field to the Table
    lRetCode = oUserFieldsMD.Add
    GC.Collect() 'Release the handle to the User Fields
    Hope it helps.
    Regards,
    Pawel

  • I want to make a textfield non editable with blinking cursor,and the text is input from a custom keypad

    I want to make a textfield non editable with blinking cursor,and the text is input from a custom keypad....
    Please Help me.
    I want to make a numpad of my own from which i can set the text but i want the user to tap in between the text..

    You seem to stop the while loop to run the following code, then the program ends. Are you running this using the "continuous run" button????
    You need one big while loop containing the acquisition, then you build up the history data in a shift register. Clicking "save" will save the data, but not stop the loop.
    Why did you place a time-control in the FOR loop??? This is just post-processing so it should just do it without any delays. I don't understand the logic in the FOR loop. You are appending arrays, but then you delete the first element at each iteraction constantly trimming data from the beginning of the appended array. Then you autoindex at the output tunnel heavily duplicating all data. Ths make s no sense!
    Can you explain how you want you data saved?
    Message Edited by altenbach on 12-16-2005 11:20 AM
    LabVIEW Champion . Do more with less code and in less time .

  • I just bought an iMac. It was to come with pages, numbers, and the presentation software (like power point). I can't find these programs.

    I just bought an iMac, It was to come with pages, numbers, and the presentation software. I can't find these programs.

    Have you checked your Purchase and Updates at the app store? You will usually need to accept them and then download/install. If that does not work, you can follow these instructions:
    http://www.apple.com/creativity-apps/mac/up-to-date/

  • How do I use page numbering and a text block in a footer in Word with the Report Generation Toolkit?

    I am creating a Word document with the Report Generation Toolkit, and LabVIEW 8.2.1. In the report I am using a template that has page numbering enabled in the center. When I try to add a text block to the left side footer, it eliminates the page numbering and adds my text on the left side. I found "Set Report Footer Text" and "Word Set Page Numbering" vi's that may be the clue to this. When I use these two vi's I either get Page 1 of 456789-001 on the left side, or if I reverse the order I get only 456789-001(text) in the left side with nothing in the center. What I would like to achieve is 456789-001(text) on the left footer, and Page 1 of 2 in the center. Is this possible and if it is, then how can I do it?

    Hi SciManStev,
    I have attached a vi where you can see how they can be made to work together. You have to design it such that one follows the other. If you don't design it that way, it results in a race condition and only one of them get executed.
    Good Luck!
    Warm regards,
    Karunya R
    National Instruments
    Applications Engineer
    Attachments:
    SciMan1.vi ‏14 KB

  • Trouble with line spacing and text flow in Indesign 6

    Hello everyone. I'm a graphic artist working with magazine layout new to Indesign. I've used Quark for years and recently came across this problem...
    Within a paragraph we'll usually use a soft return to bump certain words to the next line. However, there are occassions I'm noticing that by doing this the lines ABOVE where I'm bumping the word change and reflow. I've never had an issue with this before and it causes a serious problem for us. Is this a setting I have on that I'm not aware? What can I do to avoid this happening?
    Thank you for any input or advice.

    It's one of the major differences between Quark and ID.
    ID has a "paragraph composer" as will as a single line composer like Quark's, and it's on by default. When you use the paragraph composer the text is constantly analyzed and spacing adjusted for the best fit and appearance (according to the spacing algorithm and your justification settings) for the entire paragraph. If you force a line break, ID may adjust all the lines above as well as the lines that follow.
    If this is a "serious problem" you shoud probably witch to the single line composer. You'll find a drop down for it in the paragraph style definitin dialog under the Justification settings, or you can change an individual paragraph as a local override from the Control panel flyout menu.
    Most of us whove been ID users for some time find the paragraph composer to be one of the strenghts of ID, and feel it generates nicer looking text than a single line composer.

Maybe you are looking for