Aligning the Text in Centre for MultiLine Cells in JTable

Hi;
Does anyone know how I could make a java table that has multiline text cells AND this multiline text is aligned to center? I tried to extend JTextArea and to implement TableRenderer - multiline was OK but it did not do anything on setHorizontalAlign. If I extend DefaultTableRender than I can align the text to center but I got no multiline...
Any ideas?
Kindly to provide me a solution for this its urgent.

Hi;
Thanks for the reply,on using Text Area as renderer i.e using Multi-Line cells in JTable, i achieved the objective of displaying the text on multiple lines in the cell."In my Table there are 5 columns and i'm setting renderer on 3rd and 5th column,If the text is too large in column 5 it automatically gets wrapped off for all the cells in column 5.For column 3 my text is not so large as compared to column 5 and due to which the Text in the column 3 starts from the top for all the cells i.e (the first row in column 3 is parallel to first row in column 5 ),Now the problem is i can't display the text in the center of all cells for Column 3 .
Thanks in advance

Similar Messages

  • JTable How to align the Text in a Cell to Centre

    Hi Plese Help regarding JTable.
    I want to align the Text in the Table Cell to Centre how to align it. Im using Abstract Data Model TAble an what is the meaning of renderer and its use.. Help me out

    Here are a couple of links you should read for information on tables and renderers:
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
    http://www-106.ibm.com/developerworks/java/library/j-jtable/index.html?dwzone=java
    Here is an example of a simple renderer that will:
    a) center the text
    b) highlight the background when the cell gets focus
    This renderer is only used in two of the columns of the table.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableRenderer extends JFrame
         public TableRenderer()
              String[] columnNames = {"Date", "String", "Integer1", "Integer2", "Boolean"};
              Object[][] data =
                   {new Date(), "A", new Integer(1), new Integer(5), new Boolean(true)},
                   {new Date(), "B", new Integer(2), new Integer(6), new Boolean(false)},
                   {new Date(), "C", new Integer(3), new Integer(7), new Boolean(true)},
                   {new Date(), "D", new Integer(4), new Integer(8), new Boolean(false)}
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable( model )
                   //  Returning the Class of each column will allow different
                   //  renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              //  Create cell renderer
              TableCellRenderer centerRenderer = new CenterRenderer();
              //  Use renderer on a specific column
              TableColumn column = table.getColumnModel().getColumn(3);
              column.setCellRenderer( centerRenderer );
              //  Use renderer on a specific Class
              table.setDefaultRenderer(String.class, centerRenderer);
         public static void main(String[] args)
              TableRenderer frame = new TableRenderer();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
         **  Center the text and highlight the focused cell
         class CenterRenderer extends DefaultTableCellRenderer
              public CenterRenderer()
                   setHorizontalAlignment( CENTER );
              public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                   if (hasFocus)
                        setBackground( Color.cyan );
                   else if (isSelected)
                        setBackground( table.getSelectionBackground() );
                   else
                        setBackground( table.getBackground() );
                   return this;

  • JLabel: How to Left Align the text

    Hi.
    I created a JLabel and wanted to left align the text. However, the text is always centered in the frame that contains it. Can you tell me what I need to add to the code?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Frame.*;
    public class S extends JFrame
         public S()
              setSize(300, 300);
              setTitle("Title Bar");
              setResizable(false);          
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JLabel label = new JLabel("A label", JLabel.LEFT);
              label.setHorizontalAlignment(JLabel.LEFT);           
              label.setToolTipText("Should be left aligned");
              JPanel pane = new JPanel();          
              pane.add(label);
              setContentPane(pane);     
         public static void main(String[] args)
              S f = new S();
              f.show();     
    }Thanks
    Raja

    Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
    Layout Managers layout the components based on rules for each layout manager.
    By default a JPanel uses a FlowLayout. By default FlowLayout aligns components in the center of the space allocated to it. In your case you allocated 300 to the width of the frame, therefore the panel has a width of 300, therefore the label is centered in the 300 pixels.

  • I have updated to the new version of iPhoto but it will no longer let me edit text in the preset text boxes.  The text is highlighted for a nanosecond but will not stay highlighted so I can amend it.  Can anyone help me with this.  Many thanks.

    I have updated to the latest version of iPhoto.  But now iPhoto will not let me amend the preset text in the text boxes.
    the text is highlighted for a nano second but it will not stay highlighted so that I can add my own text.
    can anyone help me with this issue.
    Many thanks

    You might try using the add-on 'NoSquint' which allows numerous zoom options specific to each page you visit & keeps your settings - https://addons.mozilla.org/en-US/firefox/addon/nosquint/
    If you want to go back to 3.6x, you will find it here:
    http://www.mozilla.com/en-US/firefox/all-older.html
    In most cases you can simply "upgrade" (meaning downgrade) directly from the installation. It would be a good idea to save your passwords & bookmarks just to be on the safe side.

  • How to align the text in justify format with SQL Server Reporting Services?

            How to align the text in justify format In SQL server Reporting Services? Is there any code to do so?

    Hi,
    I'm afraid that if you want to have this kind of functionality, you will need to write a custom control. Here is an example: http://msdn2.microsoft.com/en-us/library/ms345265.aspx. The issue with custom controls is that it needs to be known by all the reportservers that will render your report.
    Greetz,
    Geert
    Geert Verhoeven
    Consultant @ Ausy Belgium
    My Personal Blog

  • In search results, Summary sometimes shows the top of file, not the text I searched for

    I'm searching lots of html files, it's a web site that's not imported into Sharepoint. Search is returning the correct files, but about half the time the Summary contains the text at the top of the html file, not the text surrounding the text I searched
    for. It's a big problem, users have to open the file then find the search text to see if it's useful.
    If I search for 'potato' here's an example Summary which is ok:
    All pages in issue FTDA-1983-0409:
     00010002000300040005000600070008000900100011001200130014001500160017001800190020
    … today's dieticians, the potato … most of us enjoy a
    potato cooked …
    Here's a Summary just showing text from the top of the file, 'potato' is present, but lower in the file:
    0001000200030004000500060007000800090010001100120013001400150016001700180019002000210022002300240025002600270028
    … issue: date: January 19, 1980, page …
    Could anyone help me get it to consistently show the text around the search text please?

    You can't attach a screenshot to the first post that starts a thread, but you can do that in subsequent replies.
    Does this only happen on one specific website?
    Can you post a link to a publicly accessible page (i.e. no authentication or signing on required)?
    It is possible that there is a problem with that web page and that there is a clear:both CSS rule missing that causes Firefox to start the next line at the horizontal position where the previous line ended.
    If you have made changes to Advanced font settings like increasing the minimum/default font size then try the default minimum setting "none" and the default font size 16 in case the current setting is causing problems.
    *Firefox > Preferences > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    Make sure that you allow pages to choose their own fonts.
    *Firefox > Preferences > Content : Fonts & Colors > Advanced: [X] "Allow pages to choose their own fonts, instead of my selections above"

  • Creating the text data source for 0OI_LIFNR(TD: Carrier (Number of vendor a

    Hi
    Have to create the text data source for this characteristic. Basically it is the same as 0Vendor here.
    I want to make it delta enabled.
    Am creating it on the view BIW_LFA1T(same as 0vendor)
    Can anyone advise what can I use to make it delta enabled without any code.
    Can I use numeric pointer like the 0Vendor_text.
    Many Thanks and regards,
    Kate.

    when defining a data source through the admin web page, don't add '!' in front of the password.
    ! is needed only when configuring a data source in the mapViewerConfig.xml file.

  • Reg : for Tcode IW32, where the text is maintained for the field FHKTX

    Hi GM to all,
    Can any one teme where the text is maintained for the field "FHKTX" in IW32 Tcode
    Regards
    valluru

    What is the Agent version monitoring the Database for which this alert is raised?
    You need to apply the fix for Bug : 9110313 to the Agent on the database machine.
    Refer to Note 9110313.8: Bug 9110313 - Metric clear alerts reported when warning and critical threshold are crossed

  • First time I press the space-bar the text entry hangs for several seconds

    Hi,
    When entering text, the first time I press the space-bar the text entry hangs for several seconds.
    From then on, there are no problems when entering text.
    iPhone 3G, iOS 4.2.1, no automatic correction and no spell checking.
    Thanks,
    Ofir

    Didn't resolve the problem
    There was some duplicated fonts fixed, but there wasn't the problem.
    Right now i'm writin this in Firefox and here is fine. Couldn't do this in Safari.
    I did make a video showing the problem.
    Also strange is the fact that in some tabs there isn't (aparently) the problem in Safari.
    Any other ideas?
    Tks
    http://gallery.me.com/kincas#100067/Spin%20beach%20ball

  • How to align the text vertical in the edit box in mfc?

    Hi,
    I had an edit box of which height is increased than the default.Now the problem here is when I am entering text into the edit box the text is not present at the centre of the edit box, It is still aligned at the top.
    After increasing the height of the edit box the text and cursor are aligned at the top as shown in the below figure.
    But Actually how I want is the text and the cursor position needs to be aligned centre as shown in the below figure.
    Note: "EDITTEXT        IDC_EDIT_BOX,10,73,156,14,ES_AUTOHSCROLL"
    Can anyone please help me how can I make the text and the position of the cursor to be aligned vertically i.e, to the centre of the control.
    SivaV

    If vertical alignment is not possible, then use an edit box without borders, having the default height, and place it inside a static control having
    SS_WHITERECT style. (In MFC Dialog Editor, set the Type and Colour properties). Both of controls will be children of dialog. Use a proper tab order. Check if the style
    WS_CLIPSIBLINGS is needed too.

  • How do I center align the text in my text boxes if they are currently right aligned?

    I created a client questionnaire in Word and then turn it into a PDF and created the text boxes necessary. The problem I am having in Adobe XI Pro is that I want all of the text in my text boxes to be centrally aligned rather than left aligned. However, when creating and editing the text boxes, I see no option to help me do so. When clients fill out the form it looks messy because the information that the fill in tables in not centrally aligned, so it makes my tables look poorly organised. Help would be much appreciated, thank you.

    In Form Edit mode, right-click the field(s) and select Properties - Options, and under Alignment select "Center".

  • Any description on how to use the Text Editor used for this Forum?

    I am very frustrated when trying to use the text Editing functions (without use of HTML, that I do not undertstand) that can be used to create Posts in this Forum .
    Can somebody point me to a good description of the Text Editor used to enter/edit Posts in this Forum? Thanks a lot in advance.

    Ian,
    Thank You very much for your answer.
    Based on your answer, I guess and fear, that there exist no "user guide" for this Text Editor.
    I will wait a little bit more to see whether I get more information/answers. If not, i will probably write a "Feature Request" to request that Adobe provides us or point us to a reasonable User-Guide for this Text Editor.

  • Aligning the text of a JCheckBox

    Hi,
    I have a JCheckBox that changes its value based on some action. If the text assoiciated is too long, i want the text to be displayed in multiple lines.
    I tried using HTML tags to do the same. It is perfectly fine. But is there any other better way to do this ?
    Any help will be apprciated.
    import javax.swing.*;
    import java.awt.*;
    public class CHECKBOX_MULTILINE {
    public static void main(String[] args)
         String label = "<html> This is a <br> swing button </html>";
         JCheckBox checkbox = new JCheckBox(label);
    JCheckBox chkbox3 = new JCheckBox();
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new FlowLayout());
    f.getContentPane().add(checkbox);
    f.setSize(300,200);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.show();
    }

    You should not use a transition with a Cutaway.
    iMovie does all rendering in one pass, and a cutaway and a transition would require two renders.
    One way to do it would be to use Final Cut Pro, which allows as many renders as you need.
    The other way would be to do the Cutaway. Then Share the Project using Export using QuickTime in Apple Intermediate Codec. Import this rendered clip back into an iMovie Event. Then apply a transition.

  • Using editor for multiple cells in JTable

    Hi,
    Here is my requirement -
    On clicking any column of a particular row in a JTable, a pop-up window containing the cells of that row will be displayed as JTextFields for the user to enter the value and on pressing OK, the entered values should be set in the corresponding columns of that row.
    I used a customised editor for this and the problem here is - getTableCellEditorComponent() method returns the cell value which got clicked/selected by the user. But in my case, all the cells have to be edited and returned to the corresponding columns in the table. The same is the problem with the method getCellEditorValue().
    So, please let me know how do i resolve the above issue?
    Thanks in advance!!

    Hi,
    No, the problem is not with showing the popup. I can get the pop-up containing the fields corresponding to each column in the Jtable and in the pop-up window, I have to change the Text fields and press OK.
    After pressing OK, the changed values in the pop-up will be rendered on the corresponding columns of the JTable.
    So, while using the customised editor, when the pop-up is displayed, the method public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) is basically used to return the selected component (cell).
    I can do the above using
    TableModel model = table.getModel();
    model.getValueAt(table.getSelectedRow,column)
    for all the columns but cannot return all these cells. Only one editorComponent can be returned.
    Similarly, after getting the pop-up and changing the values and pressing OK, getCellEditorValue() will be called which returns the edited cell value, again all the cell values cannot be returned here.
    So, is there a way by which all the cells of a particular row can be edited at a time? Hope the explanation is clear now.
    Please help!
    Thanks in advance!!

  • Multiline cells in JTable

    Hi all,
    Im created a JTable,but im not able to read the lengthy text when it is bigger than the cell width.So, i want the text to be be align in the next line of that cell same as in excel sheet.
    Can anyone help me in this.
    Thank you

    Im created a JTable,but im not able to read the lengthy text when it is bigger than the cell width.So, i want the text to be be align in the next line of that cell same as >in excel sheet.You should look at using your own cellRenderer ( TableCellRenderer)
    Regards,
    Alan Mehio
    London,UK

Maybe you are looking for

  • Putting .avi files onto DVD

    I'm not sure if this is the correct forum for this question (and I can't seem to find any other threads about it), but I have a bunch of TV Shows in .avi format on my computer. I'd like to be able to place them on a DVD where I can simply watch them

  • Importing XML Templates

    Hi, Currently I am using Adobe Framemaker to import XML templates and make tables of data. Once the data has been imported into Framemaker it is easy to manipulate (change colours/sizes of columns etc.) However, I am looking for a way to do this work

  • Question re authorising my computer

    I installed Digital Editions and tried to authorise my computer but got a message saying "Activation Server Error - Code E_AUTH_NOT READY".  What does this mean?  What do I do now?

  • Plug-ins missing

    I just did a system update and notice that flash is not working on any sites. So I installed flash from adobe site. Still no luck. When I go to Safari Help menu and select "Installed Plug-ins" -- I get a blank HTML page -- as if Safari no longer sees

  • Playback jitter on SMIL with a seq of multiple videos

    I notice jitter on the playback via a smil script with a seq of mulitple videos clips. The jitter appear to start on the second and subsequent video clips. The videos clips have the same resolution and bitrate via HTTP Progressive playout. Is there s