Highlighting text in a table cell

Im trying to get text in a table have it background shaded a different colour to the rest of the table cell but it doesnt work. No exceptions are thrown does anyone have any idea.
public Component getTableCellRendererComponent(JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column)
        setFont(table.getFont());     
        this.setText(value));
        this.selectAll();
        this.setSelectionColor(new Color(0,0,255,100);
        return this;
    }

The answer is similar to what someone else asked recently for highlighting text in a JFormattedTextField cell.
class MyFocusListener extends FocusAdapter
public void focusGained(FocusEvent e)
SwingUtilities.invokeLater(new Runnable()
public void run()
selectAll();
Put that in your cell editor or its base class. You can change the color or whatever you want. I think the problem is a timing thing where normal focus processing is interrupting your changes. So give the focus processing time to run with this Runnable triggering your processing to occur on the Awt thread (as is proper) after the system is doing whatever it wants to do. Let us know if it works for you.

Similar Messages

  • Text Wrapping in table cell

    Hi folks
    If the text in a table cell exceeds the width of cell then is it possible to make that cell scrollable.
    Or either can we scroll only text horizontally.
    I know PopIn is alternate for this problem but see if it is possible.
    Thanks is anticipation,
    Mandeep Virk

    Hi Guys thanks for quick response,
    I tried it using text wrapping but i did;nt see any difference. Can u please explain a bit it text wrapping is true then how a normal line will appear.
    Is using text wrap the text comes in two lines or have some what different feel.
    Mandeep virk

  • Can't vertically center text within a table cell with a picture next to it

    I have a table and each cell has a picture in it (which was "cut" from another part of the document and "pasted" into the cells). Next to it, I typed a few words. I want the words to be centered vertically within the cell. However, everytime I click on the vertical centering in the inspector, it moves the picture and the text remains at the very bottom of the cell. The text is "tied" to the picture. I've tried everything... highlighting the text, same thing. Can't figure it out!! Is there any way to do this without inserting text boxes??

    Vertical align works on text within text boxes and within table cells.
    I have just checked this using a table with:
    *1st cell* Inline Picture with caption under. Cell sizes to fit
    *2nd cell* Same as first, picture scaled down. Text and image centre vertically.
    *3rd cell* Caption only, vertically centred.
    It works and I have wrap turn off on the image, before I pasted it in.
    On rereading the O.P.'s post it seems to be saying contradictory things. That the text is "tied to the picture" which is what you would expect of inline graphics and that the text is stuck in the bottom the cell.
    Without a picture and a better description of the problem we are none the wiser.
    I am just guessing but perhaps the O.P. has the image and Inline graphic on the same line and can't understand why the bottom of the text and the bottom of the image are aligned.
    If this is the case it is a misunderstanding of what inline graphic means. The image acts just like a character in the text and sits on the text baseline, it is not an independent object.
    It is possible to shift text next to the image or the image itself by selecting either and altering:
    +Inspector > Text > More > Baseline Shift+
    But frankly you would be better separating the 2 and putting the text in the cell to the left or right of the image.
    Peter

  • Highlighting text in a table

    I want to highlight text (colored band) in a table. Not able to do so. The highlighting icon goes off when the cursor is on the text in table. It reappears when the cursor is outside the table.

    Hi Fruhulda,
    Thanks.
    The method shown below also works. But one has to be careful because among the menu options shown is "document color" (icon nos 4 from left). This is the correct one. I had been trying the icon for text color ignoring document color because it reads as if it for the entire document. Just now I tried the document color and it worked as a highlighter after the text was selected.

  • Text Box in Table Cell

    I'm attempting to insert a text box into a table cell but can't. I can't drag one in there either. Are there settings I need to adjust to make this work?

    I don't believe you can insert a text box into a table cell, but you can place a text box on a table cell. The trick is to make the text box floating with wrap turned off.

  • Unable to highlight text in ibook table (on Ipad ) created with ibook author

    Text I enter onto table   is not highlitable when viewed on iPad.
    Suggestions?

    The way i enter text onto table:
    select table cell, double click, enter text, press tab.
    It looks its a standard procedure
    export as ibook
    many thanks

  • Select text of edited table cell

    Hello,
    I would like to have the text selected of a table cell i am editing. When i double click the cell, i can change the content of the cell, but i should manually select the text first.
    I would like to have this text selected automatically.
    Thank you in advance,
    Rene Boere

    Add a focus listener on the text field you are using in the cell editor. When the text field gets focus, tell it to select all of it's text. Something like this maybe:final JTextField tField = new JTextField();
    tField.addFocusListener( new FocusListener() {
        public void focusGained( FocusEvent fe ) {
            tField.selectAll();
        public void focusLost( FocusEvent fe ) {

  • Highlighting input field and  table cell column in red colour

    Hi,
           I have 4 input fields and a table in my screen. All the input fields are read only.
        I have a functionality where I have to highlight a input field with the red colour. In the sense, I have to put a thin Red border over the input field without thowing any errors or messages.
           Also, i have to highlight a particular cell in the table. i.e, i have to put Red colour border over the cell of the table for some rows only. Right now i have changed the background colour of the cell for required rows, but i need Red thin border rather than changing the entire background colour.
    Please guide me on achieving these functionalities..
    Thanks and Regards,
    -Shabir Rahim.

    Hi,
    The red thin lines border you are talking about comes from the framework during the exceptions. If this is the case then refer the following links, hope this will help you.
    [Re: Automatic message for inputfields with state=required]
    [Re: Validation of InputField]
    Well without exceptions, i dont think it will come.
    thanks & regards,
    Manoj
    Edited by: Manoj Kumar on Feb 7, 2008 12:09 PM

  • [pages 5.0.1] How can I add Pictures to the Text in a Table cell?

    Hi,
    is it possible to add a graphic to a cell in a table, where i have already entered some text?
    Everytime I insert the graphic, Pages makes it to the cell's background...
    Can anyone help me?
    Thanks.

    The feature to add images in tables is gone, ike about another 90 features that exists in Pages 09.

  • How do i delete text from a table cell

    I want to delete text from a cell or table but not the cell or table themselves. How do I do this? The 'delete' function does not work.

    Mac Word 2011. i found the answer: 'fn' (function') key + 'Delete' key. if i had a full desktop keyboard it would be the 'Del' key, NOT the 'Delete' key.

  • Text Formatting within table cells

    This is probably a very beginner-type question.
    I am using tables to create a page structure, with an 800x600
    table encompassing 3 columns (two outermost two the nav bar and a
    column with pictures in it.) The inner cell will be where I place
    the majority of the text on my page. However, when I try to type in
    the cell it always starts in the middle of the cell, and will never
    start at the top of the cell. How do I fix this?

    Set the vertical alignment of the cell to "top" using the
    "valign" field on
    the Property inspector when you click in the cell. And get a
    good HTML
    book. 8)
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Darth Gordolf" <[email protected]> wrote in
    message
    news:evm5ef$2u5$[email protected]..
    > This is probably a very beginner-type question.
    > I am using tables to create a page structure, with an
    800x600 table
    > encompassing 3 columns (two outermost two the nav bar
    and a column with
    > pictures in it.) The inner cell will be where I place
    the majority of the
    > text
    > on my page. However, when I try to type in the cell it
    always starts in
    > the
    > middle of the cell, and will never start at the top of
    the cell. How do I
    > fix
    > this?
    >

  • Dragging Text in Table Cell

    In older versions of Pages, dragging text from a table cell into another table cell would cause the 2 cells to swap text. In '09 the dragged text overwrites the text in the cell it's dropped into. Is there a way to go back to the old way?

    No not that I know of.
    I have tried all the possible keyboard combinations and none do what you want.
    Peter

  • Set text in table cell to bold

    I am trying to get the text in a table cell to alternate between plain and bold on a ctrl-click.
    The setFont() statements seeming have no effect.
    Can anyone help?
    Self Contained thing here:
    package boldTableCell;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    public class MyTable extends JTable implements MouseListener {
         private boolean isBold = false;
         private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
         private Object[][] data = {
                   {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)},
                   {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
                   {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)},
                   {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)},
                   {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)},
          * constructor
         public MyTable() {
              super();
              DefaultTableModel defaultTableModel = new DefaultTableModel(data, columnNames);
              this.setModel(defaultTableModel);
              this.setName("My Table");
              setListeners();
          * set listeners
         private void setListeners() {
              addMouseListener(this);
         // on ctrl-click in variable column, flip bold/not bold
         @Override
         public void mouseClicked(MouseEvent event) {
              System.out.println ("mouseClicked(): # of clicks: " + event.getClickCount());
              // ctrl -click
              if ((event.getModifiers() & ActionEvent.CTRL_MASK) > 0) {
                   System.out.println("ctrl-click");
                   Point point = event.getPoint();
                   int row = rowAtPoint(point);
                   int column = columnAtPoint(point);
                   // if not valid then return
                   if ( row < 0 || column < 0) {
                        return;
                   // if this click was on the variable column
                   if (column == 0) {
                        System.out.println("ctrl-click on column 0 ");
                        Component component = super.prepareRenderer(this.getCellRenderer(row, column), row, column);
                        // now get the current font used for this cell
                        Font font = component.getFont();
                        isBold = ! isBold; // flip boolean
                        if (isBold) {
                             System.out.println ("ctrl-click: bold: " + isBold);
                             component.setFont(font.deriveFont(Font.BOLD));
                             component.setForeground(getForeground()); // otherwise text disappears
                             //     (JLabel)t.getHeaderRenderer()).setFont(new Font(("Courier", Font.BOLD, 12));
                        else { // not bold
                             System.out.println ("ctrl-click: not bold: " + isBold);
                             component.setFont(font.deriveFont(Font.PLAIN));
                             component.setForeground(getForeground()); // otherwise text disappears
                        component.invalidate();
                        component.repaint();
                        this.invalidate();
                        this.repaint();
                   } // end if click on definition column
         } // end mouseClicked
         @Override
         public void mouseEntered(MouseEvent arg0) {
         @Override
         public void mouseExited(MouseEvent arg0) {
         @Override
         public void mousePressed(MouseEvent arg0) {
         @Override
         public void mouseReleased(MouseEvent arg0) {
          * @param args
         public static void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   e.printStackTrace();
              final JPanel jPanel = new JPanel();
              final MyTable myTable = new MyTable();
              jPanel.add(myTable);
              final JFrame frame = new JFrame();
              frame.add(jPanel, BorderLayout.CENTER);
              frame.setTitle("My Panel");
              frame.setPreferredSize(new Dimension(400, 150));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(300, 200);
              frame.pack();
              frame.setVisible(true);
    }Edited by: allelopath on Jul 8, 2010 11:06 AM
    Edited by: allelopath on Jul 8, 2010 11:07 AM

    got it
    package boldTableCell;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    public class MyTableWithCustomRenderer extends JTable implements MouseListener {
         private boolean isBold = false;
        private List<Boolean> isBoldList;
         private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
         private Object[][] data = {
                   {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)},
                   {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
                   {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)},
                   {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)},
                   {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)},
          * constructor
         public MyTableWithCustomRenderer() {
              super();
              // initialize bold for each row to false
              isBoldList = new ArrayList<Boolean>(5);
              for (int row = 0; row < 5; row++) {
                   isBoldList.add(row, false);     
              DefaultTableModel defaultTableModel = new DefaultTableModel(data, columnNames);
              this.setModel(defaultTableModel);
              this.setName("My Table");
              setListeners();
          * set listeners
         private void setListeners() {
              addMouseListener(this);
         // on ctrl-click in column 0 , flip bold/not bold
         @Override
         public void mouseClicked(MouseEvent event) {
              // ctrl -click
              if ((event.getModifiers() & ActionEvent.CTRL_MASK) > 0) {
                   System.out.println("mouseClicked(): ctrl-click");
                   Point point = event.getPoint();
                   int row = rowAtPoint(point);
                   int column = columnAtPoint(point);
                   // if not valid then return
                   if ( row < 0 || column < 0) {
                        return;
                   // if this click was on column 0
                   if (column == 0) {
                        isBoldList.set(row, ! isBoldList.get(row)); // flip boolean for this row
                        this.invalidate();
                        this.repaint();
         } // end mouseClicked
         @Override
         public void mouseEntered(MouseEvent arg0) {
         @Override
         public void mouseExited(MouseEvent arg0) {
         @Override
         public void mousePressed(MouseEvent arg0) {
         @Override
         public void mouseReleased(MouseEvent arg0) {
        @Override
        public Component prepareRenderer (TableCellRenderer renderer,int row, int column) {
            Component component = super.prepareRenderer(renderer, row, column);
            // now get the current font used for this cell
            Font font = component.getFont();
            if (column == 0) {
                 if (isBoldList.get(row)) {
                      System.out.println ("prepareRenderer(): ctrl-click: bold: " + isBold);
                      component.setFont(font.deriveFont(Font.BOLD));
                      component.setForeground(getForeground()); // otherwise text disappears
                 else { // not bold
                      System.out.println ("prepareRenderer(): ctrl-click: not bold: " + isBold);
                      component.setFont(font.deriveFont(Font.PLAIN));
                      component.setForeground(getForeground()); // otherwise text disappears
              return component;
          * @param args
         public static void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   e.printStackTrace();
              final JPanel jPanel = new JPanel();
              final MyTableWithCustomRenderer myTable = new MyTableWithCustomRenderer();
              jPanel.add(myTable);
              final JFrame frame = new JFrame();
              frame.add(jPanel, BorderLayout.CENTER);
              frame.setTitle("My Panel - Custom Renderer");
              frame.setPreferredSize(new Dimension(400, 150));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(300, 200);
              frame.pack();
              frame.setVisible(true);
    }Edited by: allelopath on Jul 8, 2010 2:07 PM

  • Styled Text in Table Cell

    Hi,
    I've got this problem: I'd like to insert a styled text in some cells of a JTable.
    The text should be composed of two kinds of Font, to emphasize some characters in it.
    Suppose I've done a class Test, that extends JPanel. In this class I've done a method appendChar(String c, boolean bol). With this method I can add a JLabel with only a single char (String of length 1) at a time. If bol is true, it emphasizes the char; if false, it uses the "default" font. For example:
    "this is an example"
    This class works fine, but I don't have any idea on how I could be able to insert a Test instance in a JTable cell.
    I think I should create a class that implements TableCellEditor, or extends DefaultCellEditor.. but I don't know how this should be done.
    If there is some other way to have some styled text in a table cell, tell me!

    Hi,
    AFAIK, the default renderer for a table cell is a JLabel in which you can display styled text using html. You would need to provide a custom editor only if the default textfield doesn't fulfil your needs. For rendering, you need to override the renderer.
    Cheers,
    vidyut

  • "No text target or text model" when accessing notes inside table cells.

    I'm using the InDesign Automation Objects through Delphi to scan all the notes inside a document and that works fine as long as the notes aren't inside tables.
    For those notes inside tables as soon as I try to get the instance for a note I get the error "No text target or text model". Tried several ways of scanning the document to get to the notes but it doesn't make a difference.
    Here's my code:
        for I := 1 to FDoc.Stories.Count do
          for J := 1 to FDoc.Stories.Item[I].Tables.Count do
            for K := 1 to FDoc.Stories.Item[I].Tables.Item[J].Notes.Count do
              Note := FDoc.Stories.Item[I].Tables.Item[J].Notes.Item[K];
    The last line throws the error.
    This seems like an InDesign bug, or is there maybe something wrong with the document or a different way to get the note content?
    Thanks.

    intolight wrote:
    > i'm bewildered by this behavior. I was building a site
    last night and
    > everytime i put text in a table cell it appeared bolder.
    No other attributes
    > were changed by me. Didn't matter if i typed it new or
    pasted text from outside
    > the table. Whne put in a table it goes heavier or
    bolder. . I don't remember
    > this ever happening before.
    >
    > As a matter of fact as a work around i was able to take
    a table from a
    > previous web page that has text in a table cell that
    doesn't go bold and paste
    > that into the new document and type over that text. But
    i don't want to have to
    > do that all the time.
    >
    > Am i going crazy? Ok you don't have to answer that. But
    please help me fiqure
    > out what's going on here. thanks!!!
    >
    >
    > page with text going bold in table cells
    >
    http://intolight.biz/text/
    >
    > page where text doesn't go bold in table cells
    >
    http://www.intolight.biz/ai/frame_index.htm
    >
    It's a table heading (th) and most browsers (all?) turns such
    tag bold.

Maybe you are looking for