How to Set a line's BackGroundColor in JTextPane?

I want to change a whole line's(not only the characters) background color.(display as we set breakpoint in a debug environment).
i tried
DefaultStyleDocument.setCharacterAttributes(start,end-start,MyAttr, false);
This can not set whole line but the begin to the end of the characters in line.
Help,and Thanks

This isn't exactly what you want, but it may give you some idea on how to approach it.
import java.awt.*;
import java.net.*;
import javax.swing.*;
import javax.swing.text.*;
public class BackgroundLines extends JFrame
     public BackgroundLines()
          throws Exception
          JTextArea textComponent = new JTextArea()
               public void paintComponent(Graphics g)
                    Rectangle drawHere = g.getClipBounds();
                    int lineHeight = g.getFontMetrics().getHeight();
                    int startOffset = getInsets().top;
                    int start = (drawHere.y / lineHeight) * lineHeight + startOffset;
                    int startLineNumber = (drawHere.y / lineHeight);
                    int endLineNumber = startLineNumber + (drawHere.height / lineHeight) + 1;
                    for (int i = startLineNumber; i <= endLineNumber; i++)
                         g.setColor( i % 2 == 0 ? getBackground() : Color.lightGray );
                         g.fillRect(drawHere.x, start, drawHere.width, lineHeight);
                         start += lineHeight;
                    super.paintComponent(g);
          textComponent.setOpaque( false );
          JScrollPane scrollPane = new JScrollPane(textComponent);
          scrollPane.setPreferredSize(new Dimension(300, 250));
          getContentPane().add( scrollPane );
     public static void main(String[] args)
          throws Exception
          BackgroundLines frame = new BackgroundLines();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);
}

Similar Messages

  • How to set border lines in table and also in template in the smartforms ?

    How to set border lines in table and also in template in the smartforms ?
    As I have to create table with following detals
    total row = 3
    row1 = 3 column
    row2 = 6 column
    row3 = 9 column
    for 2nd and 3rd row data to be fetched using coding.
    so can anybody explain me what should i use
    Table or Template ?
    and I want the border like excel format.
    Can anybody suggest me ?
    Thanks
    naresh

    if the data is multiple i.e. line items choose table.
    if the data is single i.e. fixed choose template.
    Create table
    >  Draw u r no lines
    > choose option select pattern
    > select display framed patterns
    Choose u r required one.
    out lined, or full lined. u can choose option.
    same procedure to be followed for template also.
    with regards,
    Kiran.G

  • How to set a line of table as read only during runtime?

    How to set a line (or a cell) of table as read only during runtime?

    hi wei
          when you create a table keep the readonly property of table as false
    you create the columns of table as inputfield.you bind the readonly property of
    the inputfield to two context variables
    say one for all the columnfields you to want always have as readonly and let this contextattribute of type boolean and let this be attr1
    and another for all the columnfields you donot want to be readonly and let this contextattribute of type boolean and let this be attr2
    initially set the context attributes attr1 and attr2 as true so the entire table is readonly.
    based on the condition you want to check change the attr2 to be false.
    if(your condition)
    wdcontext.currentcontextelement.setattr2(false);
    hope this helps.
    regards
    saravana

  • How to set dash line color(two colors)?

    hello all:
    Does anyone know how to set dash line color in java?
    I only know how to set line color with a single color.
    g2.setColor(Color.black);
    g2.setStroke(dashed);
    g2.draw(new Rectangle2D.Double(50, 50, 200,100));
    what I need to implement is two colors interleave on the dash line.
    so that dash line looks like this:
    ==== ====
    red white red white
    thank you for any comments.
    -Daniel.

    create 2 strokes, space them appropriately, draw the rectangle twice.

  • How to set vertical line in SAPScript

    Dear All,
    I have to set vertical line at a particular position of SAPScript. Here the lines are of varying length. Can you suggest how to do that?
    Line 1......................            | Vertical Line
    Line 2.........................         | Vertical Line
    Line 3...............                   | Vertical Line
    Thanks and regards,
    Atanu

    Hii
    use this
    BOX WIDTH 0 FRAME 10
    BOX HEIGHT 0 FRAME 10 
    BOX WIDTH 5 CM  HEIGHT 1 CM FRAME 10 TW INTENSITY 10
    BOX WIDTH 7 CM  HEIGHT 5 CM FRAME 10 TW INTENSITY 10
    HOPE THIS HELPS
    Thanks & Regards
    Naresh

  • How to set divider line in Project Task List?

    Hi
    Does anyone know how to set the position of the divider line in project task list?
    Thanks

    Hi,
    As I understand, you would like to customize divider line between task list view and grantt view.
    You could press F12 to locate the CSS code of this line, then customize it via CSS style code.
    In addition, the line could move by clicking it via Mouse. If you think Gantt view is not clear enough, you could click Zoom in or Zoom out to adjust it.
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How to detect the line wrap event of JTextPane?

    Hi all,
    I'd like to detect the line wrapping event of JTextPane, so as to adjust the visible rows of JTextPane. How could I do this? Thanks!
    Yi Bing

    there is no wrap event.
    Wrap happens during relayout. The event which invokes relayout could be different. E.g. change size or chane model (document).
    Just add document listener and componnet listener.
    Regards,
    Stas

  • Re: How to set the line height of a Label?

    In Java 8, set the graphic of the label to a TextFlow with line spacing set.
    Text text = new Text("This is my\nspaced text.");
    TextFlow flow = new TextFlow(text);
    flow.setLineSpacing(13); // default font size is 13px, so this effectively makes the text double spaced, e.g. one line of text, one blank line, another line of text, another blank line, etc.
    Label label = new Label();
    label.setGraphic(flow);
    For Java 7, I don't know how you would set line spacing for a label.

    In Java 8 you can do it even more simply:
    Label label = new Label("This is my\nspaced text");
    label.setLineSpacing(13);
    The line spacing property can also be set with css:
    .label {
    -fx-line-spacing: 13;
    Of course, none of that actually helps to do this in Java 7. If you're not wrapping the text, you can fairly easily split the text at new lines, and add a label for each line to a VBox, specifying the spacing for the VBox as required.
    If you're wrapping text, trying something similar gets ugly rather quickly.

  • How to set primary line...

    Hello,
    I'm currently using a PAP2T with the two lines enabled.  I would like to configure the adapter so that all incoming calls will only come to one of the lines.  Is this possible?  How do I do this?
    Thanks,

    Hi,
    Line1 - register YES, call without registration NO (YES is also possible, but NO will cause no dialtone when registration fails), IP dialing YES
    => primary line, this one will be ringing one as sendng "regstration" makes the VoIP provider aware of the "alive" device and where to send "calls"
    => register YES makes it a "primary" line, call without registration NO makes dialtone on this line only appears when device is registerred.
    Line2 - register NO, call without registration YES, IP dialing YES
    => secondary line, not ringing on incomming calls, VoIP operator will not "know" about this line except if it's calling
    => register NO makes it a "secondary" line, call without registration YES makes dialtone sound on this line anytime and allows calls
    =================
    => IP dialing YES is not related to your problem, it's only handy "nice_to_have" feature allowing adapter/YOU to call IP address of another
         similar VoIP adapter/VoIP phone on any IP address it can directly reach ... without involving VoIP operator ... and thus free
         (this works for adapters in same network, and/or for adapter sitting on public IP addresses or with port redirects from public IP addresses)
         this can be useffull for friends - your friend has to tell you what his/her IP address/port is ... and you can call.
    For example, to call "number" 55577923 on IP address 86.97.108.209 port 5061 you will dial this on your phone :
    55577923*86*97*108*209*5061 ... (in fact, you call sip:[email protected]:5061) - if such an adapter with
    the given number shall be connected on the mentioned IP address and set SIP port to 5061, the adapters will talk directly.

  • How to set JTree lines invisible?

    Hi all,
    I have tried it with adding following code while GUI is initializing.
    here i'm using a custom TreeCellRenderer. But still line are visible :(
    MyTreeCellRenderer renderer = new MyTreeCellRenderer();
    renderer.setBackgroundSelectionColor(new Color(0xffffff));
    renderer.putClientProperty("JTree.lineStyle", "None");
    setCellRenderer(renderer);How to get the thing done correctly?
    kaushalya

    This client property should be set to the tree, not the renderer.
    Anyway it will only work in Java look and feel (Metal).
    Read the tutorial: [Customizing a Tree's Display|http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display]

  • How to set each line without gap??

    Hello!!
    Could any one help me in setting the records in each line without gap while printing? Right now, each record gets printed with one gap inbetween. I dont want the gap, rather I want to print the records in those gap so that the page usuage will be less, otherwise double usage.
    Regards
    Mitto

    check the Vertical Elasticity of your repeating frame and your fields. If you set it as Variable, it will not use the fixed space like it does now. Play with it and see how it works out for you.

  • How to set some line in ALV-OO as selected

    Hi,
    i use ALV-OO and will set some outputlines before first output as selected.
    Example:
    i have an output of 10 line. I will set line 2, 6, and 9 with default as selected because some valuy is greater as 1000.
    I will set it befaore the first output. Is this possible?
    Regards, Dieter

    Hi Himanshu,
    i have tested it and first it works like i want.
    But in second way i think in our case it's better to take editory checkboxes.
    Thanks for answer.
    Regards, Dieter

  • How do i set a lines steepness and intercept

    I am trying to add a trend-line (as posted earlier) and do not know how to set a lines intercept of steepness please help
    (its a shape)
    and if possible how do i set its thickness

    Just apply what was described in the other thread.
    In column A I entered the numerical X values.
    In column B I used =A&"" to convert the numerical values into strings
    In column C I entered the Y values
    I will describe colum D later
    In A15 I entered:
    =MIN(A2,A12)
    In A16 I entered:
    =MAX(A2,A12)
    In C15 I entered:
    =FORECAST(A15,C2:C12,A2:A12)
    In C16 I entered:
    =FORECAST(A16,C2:C12,A2:A12)
    In cells D2 thru D12, I entered:
    =C$15+(C$16-C$15)*A/(A$16-A$15)
    Given that, I selected cells B2 thru D12 and asked for a line chart.
    I selected the blue line and, using the stroke button, I defined its stroke to 1.
    Yvan KOENIG (from FRANCE lundi 5 janvier 2009 14:05:15)

  • How do I set multi-line tabs?

    ''locking as a dupe - http://support.mozilla.com/en-US/questions/763250''
    Please tell me how to set multi-line tabs. Having one looong line of open tabs is a serious waste of time, so certainly it must be possible in Firefox to stack 'em up . . . Right?

    http://support.mozilla.com/en-US/questions/763250

  • File adapter-How to set line break in text file-split record into two lines

    Dear Guru's,
    I have to solve following problem with XML (with mulitiple records) to TEXT file scenario using file adapter. I have to output for ever ONE data record in XML always two identical lines in text file. Second line should have a little bit different mapping in few fields like date,... So I did duplicate fileds in my output structure in mapping and need to know how to set line break in the middle and see half of structure in first line and next structure half in second line
    My output structure in mapping is:
    CASHFLOW
    - INTERFACE
    - GESELLSCHAFT
    - ANWENDUNG
    - PRODUKT
    - VERTRAG
    - BETRAG
    - WAEHRUNG
    - DIRECTION
    - BEWEGUNGSTYP
    - FAELLIGKEIT
    - ZINSFESTSTELLUNG
    - ZAHLUNGSTAG
    - RENDITE
    - INTERFACE2
    - GESELLSCHAFT2
    - ANWENDUNG2
    - PRODUKT2
    - VERTRAG2
    - BETRAG2
    - WAEHRUNG2
    - DIRECTION2
    - BEWEGUNGSTYP2
    - FAELLIGKEIT2
    - ZINSFESTSTELLUNG2
    - ZAHLUNGSTAG2
    - RENDITE2
    Question is how can I set on receiving file adapter in Content Conversion Parameters that fields from first structure half INTERFACE...RENDITE should be outputed in one line and fields from second half of structure INTERFACE2...RENDITE2 should start on second line in final text file.
    I'm getting at the moment one line only and I need to know how can set line break so that second line starting with INTERFACE2(CA)...RENDITE2 will start in new line.
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000",CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    This should be final output:
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",2,12,2009-01-28,2009-01-27,2009-01-28,"0.0000000"
    CA,"0100","7","512",20090127010001,-12454762586.6800,"EUR",1,10,2009-01-27,2009-01-27,2009-01-27,"0.0000000"
    My file adapter settings:
    RecordsetStructure=CASHFLOW
    CASHFLOW.fieldNames=INTERFACE,GESELLSCHAFT,ANWENDUNG,PRODUKT,VERTRAG,BETRAG,WAEHRUNG,DIRECTION,BEWEGUNGSTYP,FAELLIGKEIT,ZINSFESTSTELLUNG,ZAHLUNGSTAG,RENDITE
    CASHFLOW.fieldSeparator=,
    CASHFLOW.endSeparator='nl'
    CASHFLOW.fieldNames=INTERFACE2,GESELLSCHAFT2,ANWENDUNG2,PRODUKT2,VERTRAG2,BETRAG2,WAEHRUNG2,DIRECTION2,BEWEGUNGSTYP2,FAELLIGKEIT2,ZINSFESTSTELLUNG2,ZAHLUNGSTAG2,RENDITE2
    CASHFLOW.fieldSeparator=,
    It wont help if I add two identical structures in mapping because in output i would see for multiple entries section with first lines only and after that section with second lines only. And CASHFLOW is one part of more complex mapping ...
    (This is final output structure RecordsetStructure=HEADER,CASHFLOW,CONDITION,REFERENCE,CONTRACT - more sections with different data and all these should have duplicate lines at the end)
    Thanks a lot for any help
    Cheers
    Marian
    Edited by: Marian  Luscon on Jul 14, 2009 11:44 AM

    Hi Ivan,
    right, I did test just for sure.
    Putting constant 'nl' into field CASHFLOW-INTERFACE1 didnt help - still getting one line instead two lines.
    CA ,"0100" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,2 ,12 ,2009-01-28 ,2009-01-27 ,2009-01-28 ,"0.0000000" ,'nl' ,"GTP1" ,"7" ,"512" ,20090127GTP101 ,-12454762586.6800 ,"EUR" ,1 ,10 ,2009-01-27 ,2009-01-27 ,2009-01-27 ,"0.0000000"
    So there is still question. Is there any way (mapping,...) how to output always 2 lines in text file for one record in XML. It always does 1 record in mapping structure = 1 line but we need 2 lines ...
    Example:
    Input: 4 records in XML
    Output: 8 lines in final text file ...
    Thanks to you all guys
    Marian

Maybe you are looking for

  • Table name for open delivery document and open billing document.

    Can any body tell me what are the table names where we can get the the open delivery document numbers and open billing document numbers?

  • Decrease size of TextField.....Help Please...

    Hi,I have developed a Layout(with the help of a colleague..Jim Andreau) which has a GridLayout and some TextFields. I need to reduce the size of the TextField.It takes the whole stretch of the layout. Transaction Number:[                             

  • Reloading Vista after a disk wipe

    I have a Paviillon 6500 Entertainment laptop that came with Vista pre-loaded.  I bought a new laptop a couple of months ago and wiped the drive of this pavillion because I originally thought I was going to junk it.  But now, if I can get Vista back o

  • How to enable VLAN traffic in Mac book Pro

    Hi i am running Yosemite OS on MACBOOK PRO 13" also windows 8.1 running on parallel V10 (the latest one). in my line of work, we use custom tools to communicate with our products, all the tools are based on windows and running in layer 2. some of the

  • Any New Drum programs UB yet? DrumCore? BFD? Anything like jamstix?

    Don't know if there are any good drum programs out there. What I sometimes still do is use groove agent or jamstix (windoze) to run BFD, or similar which gives you the option to add fills on the fly, with read/write automation (does logic have this a