How to aling the text in a JTable???

I use this code to make a vertical header like in excel. The thing is that i want to aling the text in that column but i couldn´t. I try to set the render, but i loose the header render in the column. Anyone know how to aling the text in that column with out loosing the header effect????
i post a code that i use as model for my project.
package com.chuidiang.ejemplos;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
* Ejemplo de cómo hacer una "cabecera" lateral en un JTable. Idea original de
* Leunamal en
* http://foro.chuidiang.com/java-j2se/tabla-de-referencias-cruzadas-en-java/
* Básicamente consiste en hacer que la primera columna: - No sea editable. - No
* sea seleccionable. - Tenga el mismo render que el JTableHeader superior.
* @author chuidiang
public class CabeceraLateral {
      * Crea y visualiza una ventana con un JTable que tiene cabecera en la parte
      * superior y en la columna izquierda
      * @param args
     public static void main(String[] args) {
          // Un modelo de datos que hace la primera columna (la de
          // la cabecera lateral) no editable.
          DefaultTableModel tm = new DefaultTableModel(10, 5) {
               @Override
               public boolean isCellEditable(int row, int column) {
                    if (0 == column)
                         return false;
                    return super.isCellEditable(row, column);
          // Titulos para la cabecera superior. El primero es vacio,
          // puesto que corresponde
          tm.setColumnIdentifiers(new String[] { "", "A", "B", "C", "D" });
          // Valores para la primera columna, que es la cabecera lateral.
          for (int i = 0; i < 10; i++)
               tm.setValueAt(i + 1, i, 0);
          // JTable al que se le pasa el modelo recien creado y se
          // sobreescribe el metodo changeSelection para que no permita
          // seleccionar la primera columna.
          JTable t = new JTable(tm) {
               @Override
               public void changeSelection(int rowIndex, int columnIndex,
                         boolean toggle, boolean extend) {
                    if (columnIndex == 0)
                         super.changeSelection(rowIndex, columnIndex + 1, toggle,
                                   extend);
                    else
                         super.changeSelection(rowIndex, columnIndex, toggle,
                                             extend);
          // Se pone a la primera columna el render del JTableHeader
          // superior.
          t.getColumnModel().getColumn(0).setCellRenderer(t.getTableHeader().getDefaultRenderer()); //here i set the render for the column. But when i try to aling the text, this column loose the effect.
          // Creación y visualización de la ventana completa.
          JFrame v = new JFrame("Cabecera lateral");
          JScrollPane sp = new JScrollPane(t);
          v.getContentPane().add(sp);
          v.pack();
          v.setVisible(true);
          v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}

The word is "align" not aling.
To right-align the first column, you can do this in a prepareRenderer override.    JTable t = new JTable(tm) {
      @Override
      public void changeSelection(int rowIndex, int columnIndex,
              boolean toggle, boolean extend) {
        if (columnIndex == 0) {
          super.changeSelection(rowIndex, columnIndex + 1, toggle,
                  extend);
        } else {
          super.changeSelection(rowIndex, columnIndex, toggle,
                  extend);
      @Override
      public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
        Component c = super.prepareRenderer(renderer, row, column);
        if (column == 0) {
          ((JLabel) c).setHorizontalAlignment(JLabel.RIGHT);
        return c;
    };You can find other alternatives to your approach by searching the net for "[JTable row header|http://www.google.com/search?q=JTable+row+header]"
db

Similar Messages

  • How to blink the text with in JTable Cell?

    Hi Friends,
    I am relatively new to Java Swings. I have got a requirement to blink the text with in the JTable cell conditionally. Please help with suggestions or sample codes if any.
    Thanks in Advance.
    Satya.

    I believe Swing components support HTML tags.
    So you might be able to wrap your text in <BLINK>I am blinking !</BLINK>
    tags.
    If that doesn't work, you probably have to create your own cell renderer, and force a component repaint every second or so... messy.
    regards,
    Owen

  • How to print the text in points wise in sap script

    hi friends,
    how to print the text in points wise in sap script.
    ex: if suppose paragraph consists of 15 lines. then according to one sentence or one fullstop (.) it should give point 1. like that...
    1. hai how ru.
    2. what r  u doing.
    3.where r u.
    like this i want numbering.. waiting for ur replys.
    thanks,
    kiran

    declare a counter
    data : cnt type char 4.
    print :
    cnt = cnt + 1.
    &cnt& &text&
    cnt = cnt + 1. and so on.
    or.
    if the data is in an internal table
    loop at internal_table.
    cnt = cnt + 1.
    write form.
    in script -&cnt& &text&
    endloop.
    Edited by: NIKHILKUMAR POOJARI on Nov 17, 2008 11:18 AM

  • How to print the text in only last but one page in sapscripts

    hiiiiiiiiiii,
             explian how to print the text in only last but one page in sapscripts? wher to write the code? plz if possible explain in detail with an example?

    Hello,
    The total no pages is given by &SAPSCRIPT-FORMPAGES& command.
    So u can handle the situation in ur form like this
    /: if &PAGE&  = &SAPSCRIPT-FORMPAGES&
    p1 TEXT
    /: endif
    Try in this way it may help u.
    Regards

  • Did you know how to link the text in two or more text boxes?

    Did anyone know how to link the text in two or more text boxes in Pages 5.0? Thanks for your answer.
    Qualcuno sa come collegare il testo in due o più caselle di testo nella versione 5.0 di Pages. Grazie per le vostre risposte.

    It's just one of the many, many features that have been eliminated or changed. Leave feedback for the Pages team using the link in the Pages menu and review & rate the new versions in the Mac App Store.
    If you previously had iWork '09, those apps are still in your Applications folder in a folder named iWork '09. You can continue to use them to get things done.

  • I cannot figure out how to make the text larger on an incoming email.  The finger method doesn't work and I cannot find any toolbar with which to do it.  I could find nothing in settings also.  Plese help and thank you.

    I cannot figure out how to make the text larger in a received email.  The finger method doesn't work and I can find no tool bar as I can for composing emails.  I can find nothing in settings.  Please help and thank you in advance.

    Hi there,
    Download a piece of software called TinkerTool - that might just solve your problem. I have used it myself to change the system fonts on my iMac. It is software and not an app.
    Good wishes,
    John.

  • How to use the text module in script

    hi,
            i script how to use the text modules and how to write the code  in layout of the script?

    Hi,
    You canr use text modules in script. You have to use standard texts .
    Standard text are maintained in SO10 transaction.
    you can create translation text for other languages also . So based on logon language it will print translation text.
    go to SO10
    give textname it say Ztextname  id as ST and language as EN
    say create, then you will get editor there maintain your text and save it . then come back . Now change language (say for german DE) say create and eneter translation text and save it.
    so now you have created a text called ztextname which you can use in your script.
    Inorder to insert the texts in your script do as below
    go to any window editor and   select path
    Insert->texts->symbols->standard symbols
    then you will get popup  in which you have to mention all the parameters that you have created earlier.
    after inserting just change language EN to sy-langu
    Reward points if useful
    About text elements Sravan already given some informatiomn
    Regards,
    Nageswar

  • How to clear the text in the Text Editor

    Hi all,
    I created a Text editor and also i am having language field in the screen.
    whenever i change the language auomatically the text has to change when the text exists for that
    language.
    this is working fine, but when the Text exist , the text editor should be blank.
    But it is carrying the Previous editor text itself into it .
    How to clear the text in the Editor.
    Regards,
    Madhavi

    Hello Madhavi
    The simple report ZUS_SDN_TEXTEDIT_CONTROL shows how to switch the texteditor contents when changing the language.
    *& Report  ZUS_SDN_TEXTEDIT_CONTROL
    *& Thread: how to clear the text in the Text Editor
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1145272"></a>
    *& By default the itab GT_OUTTAB contains texts in DE and EN.
    *& To switch the language directly enter into the command window:
    *& LANGU=DE, LANGU=EN or LANGU=FR
    REPORT  zus_sdn_textedit_control.
    TYPE-POOLS: abap.
    TYPES: ty_t_text     TYPE TABLE OF as4text
                         WITH DEFAULT KEY.
    TYPES: BEGIN OF ty_s_outtab.
    TYPES: language TYPE spras.
    TYPES: text     TYPE ty_t_text.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                          WITH DEFAULT KEY.
    DATA: gt_outtab       TYPE ty_t_outtab,
          gs_outtab       TYPE ty_s_outtab.
    DATA: gd_language     TYPE spras.
    DATA: go_docking      TYPE REF TO cl_gui_docking_container,
          go_textedit     TYPE REF TO cl_gui_textedit.
    DATA: gd_okcode       TYPE ui_func,
          gd_repid        TYPE syst-repid.
    START-OF-SELECTION.
      PERFORM fill_texts.
      gd_language = syst-langu.
      PERFORM init_controls.
    * Link the docking container to the target dynpro
      gd_repid  = syst-repid.
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          OTHERS                      = 4.
      IF sy-subrc NE 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      PERFORM set_text_editor.
    * NOTE: dynpro does not contain any elements
      "       ok-code => GD_OKCODE
      CALL SCREEN '0100'.
    * Flow logic of dynpro (does not contain any dynpro elements):
    *PROCESS BEFORE OUTPUT.
    *  MODULE STATUS_0100.
    *PROCESS AFTER INPUT.
    *  MODULE USER_COMMAND_0100.
    END-OF-SELECTION.
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
    *  SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE user_command_0100 INPUT.
      TRANSLATE gd_okcode TO UPPER CASE.
      CASE gd_okcode.
        WHEN 'BACK'  OR
             'EXIT'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN 'LANGU=DE' OR
             'LANGU=EN' OR
             'LANGU=FR'.
          PERFORM get_text_editor.
          SPLIT gd_okcode AT '=' INTO gd_okcode gd_language.
          PERFORM set_text_editor.
        WHEN OTHERS.
      ENDCASE.
      CLEAR: gd_okcode.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  FILL_TEXTS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM fill_texts .
    * define local data
      DATA: ld_string   TYPE string.
      gs_outtab-language = 'EN'. REFRESH: gs_outtab-text.
      ld_string = 'Good morning'.
      APPEND ld_string TO gs_outtab-text.
      APPEND gs_outtab TO gt_outtab.
      gs_outtab-language = 'DE'. REFRESH: gs_outtab-text.
      ld_string = 'Guten Morgen'.
      APPEND ld_string TO gs_outtab-text.
      APPEND gs_outtab TO gt_outtab.
      gs_outtab-language = 'FR'. REFRESH: gs_outtab-text.
      ld_string = space.
      APPEND ld_string TO gs_outtab-text.
      APPEND gs_outtab TO gt_outtab.
    ENDFORM.                    " FILL_TEXTS
    *&      Form  INIT_CONTROLS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM init_controls .
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
    *      repid                       =
    *      dynnr                       =
    *      side                        = dock_at_left
    *      extension                   = 50
    *      style                       =
    *      lifetime                    = lifetime_default
    *      caption                     =
    *      metric                      = 0
          ratio                       = 90
    *      no_autodef_progid_dynnr     =
    *      name                        =
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5
          OTHERS                      = 6.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT go_textedit
        EXPORTING
    *      max_number_chars       =
    *      style                  = 0
    *      wordwrap_mode          = wordwrap_at_windowborder
    *      wordwrap_position      = -1
    *      wordwrap_to_linebreak_mode = false
    *      filedrop_mode          = dropfile_event_off
          parent                 = go_docking
    *      lifetime               =
    *      name                   =
        EXCEPTIONS
          error_cntl_create      = 1
          error_cntl_init        = 2
          error_cntl_link        = 3
          error_dp_create        = 4
          gui_type_not_supported = 5
          OTHERS                 = 6.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " INIT_CONTROLS
    *&      Form  SET_TEXT_EDITOR
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM set_text_editor .
      BREAK-POINT.
      CLEAR: gs_outtab.
      READ TABLE gt_outtab INTO gs_outtab
           WITH KEY language = gd_language.
      CALL METHOD go_textedit->set_text_as_stream
        EXPORTING
          text            = gs_outtab-text
        EXCEPTIONS
          error_dp        = 1
          error_dp_create = 2
          OTHERS          = 3.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " SET_TEXT_EDITOR
    *&      Form  GET_TEXT_EDITOR
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM get_text_editor .
      CLEAR: gs_outtab.
      CALL METHOD go_textedit->get_text_as_stream
        EXPORTING
          only_when_modified     = cl_gui_textedit=>true
        IMPORTING
          text                   = gs_outtab-text
    *      is_modified            =
        EXCEPTIONS
          error_dp               = 1
          error_cntl_call_method = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      MODIFY gt_outtab FROM gs_outtab
        TRANSPORTING text
        WHERE ( language = gd_language ).
    ENDFORM.                    " GET_TEXT_EDITOR
    Regards
      Uwe

  • HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS

    HI,
       HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS?

    in ur script main window
    /: IF &TTXSY-PAGE& = 15.              
    ur text or standard text           
    /: ENDIF.                             
    use this.
    hope it helps if any issues revert back

  • How to enlarge the text in the "email subject/header plane"

    in Thunderbird email, the subject of the email and the email message are in to different planes. No problem enlarging the "message text, words" in the "body" of the email. How to enlarge the "text, font or words" of the "subject" in the subject/header plane? Don't want to open email if I'm not sure of it, and can't be sure of opening emails if I can't SEE the subject of the email. Surely I'm not the only one with this problem.

    Thanks! Works great!

  • How to Insert the Text in Selected Text Frame-Reg.

    Dear all,
    I am using the SnipperRunner - SDK, and create the TextFrame, but I can't insert the Text in the Particular Frame. so please give me the soultions,
    (*) Create TextFrame is ok,
    (*) Select TextFrame is also ok,
    (*) now, my Query ->
    How to Insert the Text in the Selected Frame?. (or)
    How to Link the Selectable Frame and my Text.? (or)
    How come to know the TextFrame is select?.
    Please any one can suggest me through the Coding....I will appreciate you...
    Thanks & Regards,
    T.R.Harihara SudhaN

    Hi,
    you have to get the TextModel associated with the textframe. Once you got that, ITextModel has an Insert()-method. You could also process kInsertTextCmdBoss - there are quite a few examples around. I believe WriteFishPrice also inserts text into a frame, just as an example. Good luck ...
    Bernt

  • How to wrap the text in column headers?

    Hi Friends,
    Can anyone please suggest how to wrap the text in column headers of a Java WebDynpro table?
    I believe that caption is the only UI element that a column header can have and it does not allow wrapping of the text.
    My original requirement is as follows,
    In a table I need to dynamically set the width of the columns according to the width configured by the user in some other view. All the columns of the table are dynamically rendered.
    Now what happens is when the user sets the width of the column to a rather low value, say 15 pixels, then the column is displayed like
    Supplier Catalog Name
    Sheila
    Catalog
    Name
    Dropdown
    As you can see it looks rather odd.
    Supplier Catalog Name is the header of the column and I use IWDCaption for header.
    Sheila Catalog Name Dropdown is the value of a particular row at the specified column. I am using a TextView as the TableCellEditor.
    I think what is happening here is that the framework wraps the text in the TextView according to the width specified (15px) and then the column width is extended because it can not accommodate the text (Supplier Catalog Name ) of the column header.
    We are using SAP NetWeaver Development Studio 7.0.12 as the IDE.
    I searched some forums and many people have suggested using scrollable columns but I don't understand how it will help in wrapping the text in a column header.
    Any help would be of great advantage.
    Thanks
    Amit

    Hi Deepti,
    Thanks a lot for the answer but the option that you have specified does not wrap the text. Instead it truncates the text being displayed and only the substring of the text which could be displayed in the given pixels is displayed.
    I need to show the whole text wrapped (Meaning if the width of the column is not sufficient then the text goes into the next line).
    Ayyapparaj,
    Thanks to you too for an helpful answer. It seems that the Netweaver has finally come up with a way to wrap the text in the column headers but as Manoj pointed out, I do not see the property headerTextWrapping  for a table column, Can you please specify which version of netweaver supports it?
    We are using SAP NetWeaver Development Studio 7.0.12 as the IDE.
    Thanks
    Amit Kapoor

  • How to print the texts retrived by using READ_TEXT fun module in Smartform

    Please tell me how to print the text which is rertrived by using the READ_TEXT function module in smartform.
    I have coded all things in the program lines and in that i am retriveing the long texts.
    I am getting the text lines in my internal table clearly, the thing is that I am not able to pass these lines to the text.
    I have to print the trouble ticket. in that the notes log I have to pass.
    its urgent. Points will be rewarded for any type of clue. whether it will work or not.

    There are a few ways to do it. If you need to take all of the text in the text type, in your SF text element choose "Include Text".
    Populate the fields with the data that corresponds to the text type. It is similar to the interface to the FM "Read_Text.
    Text Name
    Text Obje
    Text ID 
    Language
    Encase any variables with the "&" symbol.
    If you have already coded the call to the FM "READ_TEXT" and loaded the text into an internal table, create a loop and loop through the itab. Inside of the loop create a text element and add a variable in the text element for the field you are looking to output.

  • How to color the text  elements in script?

    how to color the text  elements in script?
    byeeeee
    plz send the answers

    Hi,
    Please go through my blog to know how to do color printing in SAP scripts.
    White Paper on 'Color Printing in SAP Scripts'
    Regards,
    Sireesha Ch

  • How to encrypt the text in password field in Oracle Forms version 6i

    Need help!
    How to encrypt the text in password field in Oracle Forms version 6i?
    one way is to change the settings in the property palette. Can somebody provide me some script to be run while the form is running which will enable the password to be encrypted?
    Thanks!

    Hello,
    Do you mean "hidden" (replaced with stars) or encrypted (that needs to be decrypted ?
    Francois

Maybe you are looking for

  • Text conversations not loading

    I use the stock messaging app and when I try to click on my conversations, the person's name shows up at the top like normal but the screen remains blank except for the word "Loading" and the little spinny thing in the middle of the screen. I have do

  • How do I set up Thunderbird to access Mediacom email account

    Trying to set up Thunderbird to access email on Mediacom email servive. should be encrypted, but Thundeerbird only finds unencrypted connection. When I try to enter settings, Tbird fails to find access. If i try to accept lower security settings, Tbi

  • Alert while goods issue about old inventory

    Hi, We have a requirement where in our client wants an alert message about old inventory aged more than 120 days at the time of issuing the same item from WBSE of lesser aging within same plant. can anybody give some idea on this? Any help on this is

  • An error occurred within the report server database. This may be due to a connection failure, timeout or low disk condition within the database

    Hello We just had this error today. We did not do ANY changes to our existing ReportServer database neither to our reports. Our infrastructure - we have sharepoint 2010 and sql server 2008 r2 with reporting services installed.  I confirmed the follow

  • Weblogic Server 8.1 with SP6

    Currently we are running with BEA Weblogic server 8.1 with service pack upgraded to SP6 lately. I heard that it will require the upgrades of Oracle database to V 9.2.0.4. Is this required? I am wondering if we need to workout this upgrade to our db.