Centering texts with DefaultTableCellRenderer

Hi,
I 've created a JTable and now I am trying to center the text in the cells of the table.
I am using an AbstractTableModel for this table and the data are store in a vector.
I tried to extends DefaultTableCellRenderer like this but it did not work because (I think) of the vector.
Here a snippet:
class centerTextRenderer extends DefaultTableCellRenderer{
public centerTextRenderer(){
setHorizontalAlignment(CENTER );
public void setValue( Object value){
setText( value.toString() );
Does anyone have a suggestion?
--kirk123

Your class looks OK (you don't even need to override the setValue() method). Did you tell your table to use your renderer?
table.setDefaultRenderer(Object.class, new CenterTextRenderer());
Note: the Java convention is to use upper case characters for all words in a class name.

Similar Messages

  • Centering text with drawString();

    Hi there! I'm putting some text inside some shapes (ellipses). So far woked great the alignment, here's my piece of code :
    Font thisFont = new Font("Arial", Font.PLAIN, 11);
              g.setFont(thisFont);
              g.setPaint(Color.black);
              FontMetrics metrics = g.getFontMetrics();
              int strWidth = metrics.stringWidth(this.objetivo);
              int h = metrics.getHeight();
              int fontXOffset = ((this.width - strWidth) / 2) + this.x;
              int fontYOffset = ((this.height + h) / 2) + this.y;Problem is when my string gets bigger than the ellipse width. I'd like to break it into new lines and than arrange it on the center of the shape.
    Any ideias???

    Yep, but considering that I don't know how many lines
    does my text will have, I wont be able to center it
    vertically. Because, a text with only one line, doesnt
    start at the same point as a text that has 3 lines,
    agree with me?I understand now: you want to center vertically as well as horizontally.
    You'll have to do 2 passes:
    1. determine how many lines the text will be broken into, but don't draw.
    2. draw the text, centered vertically, and additionally horizontally if you wish.
    You could either accumulate the TextLayouts from 1 to use in 2, or recompute them.

  • Centering Text with CS5

    Hi Folks,
    I usually add a 200px white matte around my photos, and put a couple of lines of text at the bottom to give the image a title, and to include my name.
    The two lines of text end up on two seperate text layers, and I usually just use the move tool to position / centre them "by eye" ... and 1/2 the time when I've flattened the image - converted it to sRGB profile - uploaded it to the website - linked to it from a forum etc I THEN discover that I've done a bad job of aligning the text (eg line 2 may not be centred with respect to line 1 etc).
    Just wondering if anyone has any workflows that would make this text aligning step easier? It would also be great if it were possible to have the rulers centered on the image (ie so zero is in the middle), with a couple of highlights representing the ends of the text - anyone know if this is possible?
    Many thanks,
    Cheers,
    Colin Southern

    Thanks folks,
    Problem solved, thanks to your help!

  • Centering text with drawString() in applet

    I want to draw a String in the center of my applet, is there a way to tell it to draw itself centered, or is there a way to find the width of the string to position it absolutely? Which would be easier? Thanks.

    You can use the graphics' font metrics (especially the stringWidth (String) method).
    Kind regards,
      Levi

  • I need a report in SAP which allows multiple Profit centers selection with

    Hi,
        Cany anybody help me with below issue -
    I need a report in SAP which allowing multiple Profit centers selection with :
    - Profit Center #
    - Profit center Name
    - Profit center long text
    - Profit Center group
    - the related PC node showing the BU and the product category group.
    Let me know is there any report which can provide us with all this details.
    With regards.

    Hi,
    I recommend the PCA standard drill-down or interactive reports accessible via the follwoing menu path:
    Accounting --> Enterprise Controlling --> PCA --> Infosystem --> Reports for PCA
    There are several reports which allow entering profitcenter groups or profitcenters.
    Long Text is not possible. Makes also no sense to report on Long Text.
    Best regards,
    Andreas

  • Centered text in PDF

    Hi
    I am new to this Acrobat SDK forum. I am trying to write a PDF code, but I have problems centering text. Below is a short "program" that writes the text "Centered text" starting at position x=100, y=600. But how do I center this text at some position, say x=200, y=600 ?  Can anyone help?
    - gullipeX
    %PDF-1.4
    1 0 obj
       << /Type /Catalog
          /Outlines 2 0 R
          /Pages 3 0 R
       >>
    endobj
    2 0 obj
       << /Type /Outlines
          /Count 0
       >>
    endobj
    3 0 obj
       << /Type /Pages
          /Kids [ 4 0 R ]
          /Count 1
       >>
    endobj
    4 0 obj
       << /Type /Page
          /Parent 3 0 R
          /MediaBox [ 0 0 612 792 ]
          /Contents 5 0 R
          /Resources << /ProcSet 6 0 R
                      /Font << /F1 7 0 R >>
                      >>
       >>
    endobj
    5 0 obj
       << /Length 73 >>
    stream
    BT
       /F1 24 Tf
       100 600 Td
       ( Centered text ) Tj
    ET
    endstream
    endobj
    6 0 obj
       [ /PDF /Text ]
    endobj
    7 0 obj
       << /Type /Font
          /Subtype /Type1
          /Name /F1
          /BaseFont /Helvetica
          /Encoding /MacRomanEncoding
       >>
    endobj
    xref
    0 8
    0000000000 65535 f
    0000000009 00000 n
    0000000074 00000 n
    0000000120 00000 n
    0000000179 00000 n
    0000000364 00000 n
    0000000466 00000 n
    0000000496 00000 n
    trailer
       << /Size 8
          /Root 1 0 R
       >>
    startxref
    625
    %%EOF

    Hi, Irosenth and others again.
    To try to solve my problem (because I do not know how to do this in PDF), I made a short PostScript program to check the length of the characters in Helvetiva 10 pt. A part of the program is shown below. If I have the length, I can calculate the centered position of the text in my C or Fortran program, that makes the PDF file.  This investigation gave, for instance, the lengths for A, B and W as:
    A:  6.66797
    F:  6.10840
    W: 9.43945
    When I placed the EPS file into Adobe InDesign a bit different values came out:
    A:  6.66959
    F:  6.10963
    W: 9.43942
    ... and still different in Adobe Photoshop:
    A:  6.67081
    F:  6.11075
    W: 9.44115
    I have the feeling that character lengths are given as integers in the font file (not as real numbers) and I actually have to multiply these lengths (for 10 pt. Helvetica)  with some unknown value to find the "correct" lengths of the given characters. Does anyone know the actual length of the character A in Helvetica for instance?
    PostScript program:
    /Helvetica findfont
    dup length dict begin
      {1 index /FID ne {def} {pop pop} ifelse} forall
      /Encoding ISOLatin1Encoding def
      currentdict
    end
    /Helvetica-ANSI exch definefont pop
    gsave
    /str 20 string def
    /Helvetica-ANSI findfont 10 scalefont setfont
    (A ) 50  750 moveto show
    (A)  stringwidth pop str cvs  80 750 moveto show
    (F ) 50  700 moveto show
    (F)  stringwidth pop str cvs  80 700 moveto show
    (W ) 50  650 moveto show
    (W)  stringwidth pop str cvs  80 650 moveto show
    grestore

  • Design Canvas & Centering text

    Forgive me for being a noob here but I have a couple of questions :-
    1.) How do I undock the design canvas so I can use it full screen ? At the moment, everything will only snap to the grid that is the displayed part of the design canvas - not the whole screen.
    2.) How do I centre text on the screen for instance a heading ? I've used 'text-align: center' but that of course just justifies in the output text box - not the screen.
    SPG

    (1) At the moment there's no way to do that with a single gesture, but we're merging the NetBeans 4.0 window manager so in the future that will be easy.
    For now, you can click on the "pushpin"-like icon near the top of the properties and project navigator window to cause them to slide out to the right.
    (2) To get centering like this, don't use absolute positioning. Here's what you can do: go to the Source tab, and add something like this (under body or form depending on where you want it):
    <p style="text-align: center"> Hello World! </p>
    (or use h1, h2, ... instead of p.) Output Text renders a span which is an inline tag, so you can't set the text-align directly on it. If you want to use an output text (for example to value bind it), you can first add an output text (but DON'T absolute position it: either double click on the output text item in the palette, or drop it and then go remove its position, left and top properties from the style property of the output text). Then go to the source tab, locate the h:outputText you've dropped, and add a <p style="text-align: center"> right before it and </p> right after it, e.g. "wrap the output text with a p block tag).
    Hope that helps.
    -- Tor
    http://blogs.sun.com/tor

  • I cant transform my text to 3d text with my photoshop cc what can i do? all 3d options seem to be blocked

    hello i cant transform my text to 3d text with my photoshop cc what can i do? all 3d options seem to be blocked

    Also check your system's capabilities against the Adobe Photoshop requirements:
    System requirements | Photoshop
    -Noel

  • Why can't I text with non Apple equipment?

    Why can't I text with non Apple equipment?

    You can with third party apps. You just can't use Messages in order to text since it only works with other iOS devices and Macs running Mountain Lion.
    https://www.google.com/search?q=texting%20apps%20for%20iPad

  • When texting with more than one person at a time the incoming text scrolls to top of the conversation. anyone out there with the same issue?

    while texting with more than one person at a time the incoming texts scrolls to top of conversation. anyone having this issue?

    I've heard claims it can be done, claims some have done it, and claims that it didn't work for them. This thread is interesting, some indications it should be possible, complaints that it didn't, and also an interesting work-around:
    "How do I text message multiple people at once?"
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=4822260
    You can ask Apple for iPhone changes via this link:
    http://www.apple.com/feedback/iphone.html
    Though if you're requesting hardware changes for iPhone v2 you may want to wait a week (or a month?)...they're probably going to be inundated right now by requests for software changes to the current iPhone.
    (If this has answered your question, please mark your original post as answered)

  • In a group text with two phones that use Imessage and one that does not. The person that does not, does not get my message when its sent in group text. How do i fix this?

    I have a group text with two of my friends. here's each person break down
    person 1 ATT network, using imessage
    person 2 verzion network, using imessage
    person 3 verzion network, using SMS
    All three of us are in a group chat. When person 1 sends a message, person 2 recieves it, but person 3 does not. Then when person 3 sends a message, both person 1 and 2 get it. When person 2 sends an Imessage, person 1 and 3 get it
    so the problem is when person 1 sends an imessage, it doesnt change to sms and person 3 doesnt get it, but person 2's automatilly switches it to green.
    How can person one get their phone to automaticlly switch it to green in group message while keeping on imessage?

    The quote below from http://support.apple.com/kb/HT5760 indicates that it in the situation you describe it should be going as MMS to everyone -- which is not what you are seeing actually happen (and also not what you want to happen if I understand correctly). There may be something else helpful in the link.
    Group messages will be sent using iMessage if all recipients have iMessage enabled. If not, the conversation will be sent as MMS. Group messages use MMS even if the content is text only.

  • How can I send a text with a picture attachment on my new iPhone5c?

    How can I send a text with a picture attachment on my new iPhone5c? It won't send or recieve!!.

    Does your carrier support it?
    Follow the steps in this guide.
    http://www.imore.com/how-send-photo-using-imessage

  • When i text with my new 4s the person receiving my text receives it from my email address, when i text with my new 4s the person receiving my text receives it from my email address

    when i text with my new 4s the person i send the message to receives it from my email address. how can i fix it?

    when i text with my new 4s the person i send the message to receives it from my email address. how can i fix it?

  • Why can I now highlight text with mouse pointer in Adobe Reader 9

    I just downloaded Adobe Reader X. I think I prefer Reader 9. I don't like being able to click in the document and have a flashing place mark (right terminology?) there. This is now happening in the Reader 9 version too, and I can copy text this way, but I don't want this. I didn't change any preferences. Can anyone help?

    Like I said, I didn't change any of the preferences, so I don't know why this happened. I think it only happened after I opened Adobe Reader X. I see no options in preferences for turning on or off the ability to highlight text with your mouse pointer, and I thought you were not supposed to be able to do this in Adobe Reader 9.

  • Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?

    Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?
    Picture below, many thanks for your help.
    Jason

    Back up all data before proceeding.
    Launch the Font Book application and validate all fonts. You must select the fonts in order to validate them. See the built-in help and this support article for instructions. If Font Book finds any issues, resolve them.
    Start up in safe mode to rebuild the font caches. Restart as usual and test.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, ask for instructions.
    If you still have problems, then from the Font Book menu bar, select
              File ▹ Restore Standard Fonts...
    You'll be prompted to confirm, and then to enter your administrator login password.
    Also note that if you deactivate or remove any built-in fonts, for instance by using a third-party font manager, the system may become unstable.

Maybe you are looking for

  • Safari (and FF) crashes constanly when visiting specific web sites

    Hi guys, as of couple of hours ago I'm having huge problems with almost any sort of web browsing I am trying to do. But let's start this story at the start... Few days ago I finally got a chance to get to my external hard drive and make a backup of m

  • Workflow not getting executed

    Hello friends. I am new to workflows. i  have created a sample workflow to cteate a material and then to display it. i have created all the std tasks successfully, and also in the workflow builder all is fine. but when i try to test it by executing t

  • Podcast Videocast/ Audio only not showing up in itunes podcast feed

    Hi Everyone, I work on a site called Truthdig and we can't get our latest audio (mp3) only podcast to show up in our itunes podcast feed, latest podcast episodes have been video. is this what is causing the problem? Could it be something else? Advice

  • Refresh rate on solaris 10 e450

    I have been searching all over for this, and I believe I am supposed to use kdmconfig. Problem is that kdmconfig does not appear to exist on my system (find / | grep kdmconfig. Everything works fine just cant get the resolution to change... I get all

  • What do I have to do to uninstall this pernicious filth called Vuze?

    The uninstall advice from Vuze simply isn't, one can see it's origins run true to course, Vuze freezes the trash, and every Uninstall Application I've tried to remove it with; CleanerApp, CC Cleaner, etc. has failed.  It has brought the normal day to