JTable changing borders for table cells

Hi,
I have a JTable which has columns which each represent a month for a
specified time period. For example, my table displays rows containing numeric data for March 1998 - April 2002.
I would like to create a Raised Cell for the numeric data for the first
cell in the time series and a raised cell everytime the numeric data
is under the column for January of the new year. For example,
the cell containing the data under March 1998 column should be raised and the cells containing the data for January 1999,2000,2001,2002 should be raised.
(FYI: I am using a TableModel which extends the AbstractTableModel)
Many Thanks in advance,
Alex

You need to create a custom table cell renderer to do what you are asking. It is what actually draws the cells. Just subclass the DefaultTableCellRenderer and override the getTableCellRendererComponent() method. Look at the source for that class, and just change it to add your logic to use a different border depending on the cell to be drawn.

Similar Messages

  • How do I change borders for a cell?

    Changing borders seems so easy. I select a cell, select a line type, select a color, select to underline a cell. Problem: It outlines the entire cell! I've tried it a hundred times, but it doesn't change. I must be missing something very simple...

    carlfrommichigancity wrote:
    Changing borders seems so easy. I select a cell, select a line type, select a color, select to underline a cell. Problem: It outlines the entire cell! I've tried it a hundred times, but it doesn't change. I must be missing something very simple...
    Carl,
    Do all that, then click off the table to apply the changes. By the way, and I may not need to say this, there is no Underline option. The closest thing is to apply a border style to the lower boundary of the selection.
    Jerry

  • Why do borders for some cells allow changes in line thickness, but other cells are locked in only one thickness?

    It looks like you should be able to choose different line thickness for cell borders, but for some cells you can get three choices (0.5, 1, 2 pt), but in other cases you can only do 0.5?
    I can't make a consistent thickness border around the outside of all my cells!

    VS,
    Yes, I have lots of ideas. After all that work you probably don't want to hear them.
    1. I would use PDF versions of rotated text boxes, inserted into the cells as background Fill rather than floating the actual text boxes over the table.
    2. I would never merge a cell, or divide, a cell. Too many problems await you down the road if you do that. There are many ways in Numbers to avoid having to do those things. These are things we must do in Excel to get by, but we don't have to do them in Numbers.
    3. There is a Line Type called "Thin" that has only one size, and another line type shown as a heavier solid for which the weight can be adjusted. It's possible that you have some places where you need to change the line type.
    I believe that your difficulty may come from the merging of cells causing some ambiguity as to which border needs to be selected to change the display. This would be a bug, because you should be able to just select the border and edit it, but your table may have become so complex that the program has lost track of things in the course of all your changes.
    My suggestion is to print your table just as it is, for reference, and start over in a new document, not an imported one. Don't merge or split. Use multiple simple tables and the occasional text box for annotation. You will be on your way to doing things the "Numbers Way".
    Jerry

  • How to populate change from one Table cell to more Tables??

    Dear Friends:
    I have following successfully running code, each can populate 1 table cell updating in ChangeTableSelectionMain1 change to another table in ChangeTableSelectionMain1 also, or populate 1 table cell in ChangeTableSelectionSub1 change to another table in ChangeTableSelectionSub1 also, But cannot populate table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1, Please advice how to make populating table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1 successful??
    Thanks.
    [1]. main code:
    package com.com;
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import java.awt.GridLayout;
    public class ChangeTableControl1 implements java.io.Serializable{
         private JFrame                frame;
         public static void main(String args[]) {
              try {
                   ChangeTableControl1 window = new ChangeTableControl1();
                   window.frame.setVisible(true);
              } catch (Exception e) {
                   e.printStackTrace();
          * Create the application
         public ChangeTableControl1() {
              initialize();
          * Initialize the contents of the frame
         private void initialize() {
              frame = new JFrame();
              frame.setBounds(0, 0, 1500, 675);
              final ChangeTableSelectionMain1      c1      = new ChangeTableSelectionMain1();
              final ChangeTableSelectionSub1           c2      = new ChangeTableSelectionSub1();
              JSplitPane sp = new JSplitPane();          
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              final JPanel panel = new JPanel();
              panel.setLayout(new GridLayout(1, 2));
              frame.getContentPane().add(panel, BorderLayout.CENTER);
              sp.setLeftComponent(c1);
              sp.setRightComponent(c2);
              sp.setResizeWeight(0.5);
              panel.add(sp);// add right part
                frame.addWindowListener(new WindowAdapter() {
                     public void windowClosing(WindowEvent e) {
                         System.exit(0);
                 frame.pack();
                 frame.setVisible(true);
    }[2]. ChangeTableSelectionSub1
    package com.com;
    import javax.swing.JTable;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.TableModelEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import java.awt.FlowLayout;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    public class ChangeTableSelectionSub1 extends JPanel{
           protected         JButton                bt11 = new JButton("Insert before");
           protected         JButton                bt22 = new JButton("Insert after");
           protected         JButton                bt33 = new JButton("Delete");
           protected      ChangeTableSelectionMain1 lm = new ChangeTableSelectionMain1();
    public ChangeTableSelectionSub1() {
         JPanel pnl = new JPanel();
         pnl.setMinimumSize(new Dimension(200,600));
              //pnl.setPreferredSize(new Dimension(800,600));
              final JTable tbl1 = new JTable(lm.data,lm.columnNames);
              final JTable tbl2 = new JTable(lm.data,lm.columnNames);
              JScrollPane scr1 = new JScrollPane(tbl1);
              JScrollPane scr2 = new JScrollPane(tbl2);
              lm.tbl1.getSelectionModel().addListSelectionListener(new ListSelectionListener()
              public void valueChanged(ListSelectionEvent lse)
                   if (lm.tbl1.getSelectedRow()!=-1)
                        tbl2.clearSelection();
                        System.out.print("[1]. LongguChangeTableSelectionSub get msg from LongguChangeTableSelectionMain");
                        tbl1.clearSelection();
                        revalidate();
              lm.tbl2.getSelectionModel().addListSelectionListener(new ListSelectionListener()
         public void valueChanged(ListSelectionEvent lse)
              if (tbl2.getSelectedRow()!=-1)
                   tbl1.clearSelection();
              System.out.print("[2]. LongguChangeTableSelectionSub get msg from LongguChangeTableSelectionMain");
              revalidate();
         pnl.setLayout(new FlowLayout());
         pnl.add(scr1);
         pnl.add(scr2);
         this.add(pnl);
    public static void main(String []args)
         ChangeTableSelectionSub1 c = new ChangeTableSelectionSub1();
         JFrame frm = new JFrame();
         frm.setSize(920,400);
         frm.getContentPane().add(c);
         frm.setVisible(true);
    }[3]. ChangeTableSelectionMain1
    package com.com;
    import javax.swing.JTable;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.JScrollPane;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import java.awt.FlowLayout;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    import javax.swing.*;
    public class ChangeTableSelectionMain1 extends JPanel{
           protected         JButton                bt11 = new JButton("Insert before");
           protected         JButton                bt22 = new JButton("Insert after");
           protected         JButton                bt33 = new JButton("Delete");
           protected String[] columnNames = {"First Name",
                        "Last Name",
                        "Sport",
                        "# of Years",
                        "Vegetarian"};
           protected 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)} };
           protected JTable tbl1 = new JTable(data,columnNames);
           protected JTable tbl2 = new JTable(data,columnNames);
    public ChangeTableSelectionMain1() {
         JPanel pnl = new JPanel();
         pnl.setMinimumSize(new Dimension(200,600));
              //pnl.setPreferredSize(new Dimension(800,600));
              JScrollPane scr1 = new JScrollPane(tbl1);
              JScrollPane scr2 = new JScrollPane(tbl2);
              tbl1.getSelectionModel().addListSelectionListener(new ListSelectionListener()
              public void valueChanged(ListSelectionEvent lse)
                   if (tbl1.getSelectedRow()!=-1)
                        tbl2.clearSelection();
                   if (lse.getValueIsAdjusting())
                       System.out.println("Selected from " + lse.getFirstIndex() + " to " + lse.getLastIndex());
                   revalidate();             
              tbl2.getSelectionModel().addListSelectionListener(new ListSelectionListener()
         public void valueChanged(ListSelectionEvent lse)
              if (tbl2.getSelectedRow()!=-1)
                   tbl1.clearSelection();
                   revalidate();
         pnl.setLayout(new FlowLayout());
         pnl.add(scr1);
         pnl.add(scr2);
         this.add(pnl);
    public static void main(String []args)
         ChangeTableSelectionMain1 c = new ChangeTableSelectionMain1();
         JFrame frm = new JFrame();
         frm.setSize(920,400);
         frm.getContentPane().add(c);
         frm.setVisible(true);
    }Message was edited by:
    sunnymanman

    I have following successfully running code, each can populate 1 table cell updating in ChangeTableSelectionMain1 change to another table in ChangeTableSelectionMain1 also, or populate 1 table cell in ChangeTableSelectionSub1 change to another table in ChangeTableSelectionSub1 also, But cannot populate table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1, Please advice how to make populating table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1 successful??
    My brain hurts, does yours?

  • Change Capitalization For Many Cells at Once

    How can I change the captialization for many table cells at once. I can do it for one cell at a time by triple-clicking an choosing the capitalization menu within fonts, but if I select all the cells I want to change and then go to fonts>capitalization, the capitalization menu is dimmed.
    thanks,
    Jeff

    I'm a little confused by this thread. As Badunit describes, can't you just select multiple cells and make a menu pick?
    No need for formulas, right?  (unless it's a special situation of capitalizing the start of each sentence)
    SG

  • Background to change colour of table cell?

    I have my buttons that change the backgrou color on hover but
    they dont do
    the full table cell only around the text.
    How would i get it to fill the cell?. Ive tried differnt
    padding options
    but non work.
    .buttons a:hover {
    background-color: #CC3333;
    display: block;
    TIA

    Mike wrote:
    > I have my buttons that change the backgrou color on
    hover but they dont do
    > the full table cell only around the text.
    >
    > How would i get it to fill the cell?. Ive tried differnt
    padding options
    > but non work.
    >
    > .buttons a:hover {
    > background-color: #CC3333;
    > display: block;
    >
    Then you have your code set up incorrectly because the css
    that you have
    provided should work.
    Can you provide a link to the page in question or supply the
    full
    code/css of the table in which these links are inserted.

  • Fine solid black border for table-cell

    Hi!
    I'm facing the following problem. I'd like to have a tableview where cells have a fine! black (not grey) border. The result should look like a typical Excel-Spreadsheet.
    When entering this in the css Stylesheet:
    .table-view {
        -fx-background-color: white;
        -fx-border-color: black;
        -fx-border-width: 0.8px;
    .table-cell {
        -fx-background-color: white;
        -fx-text-fill: black;
        -fx-border-color: black;
        -fx-border-width: 0.1px;
        -fx-border-style: solid;
    The border of the tablecells get grey are still are to width. How could I get my excel-like grid? When increading changing the width (i.e. to 0.5) the line gets "more black") but unfortunately also too wide.
    Thanks in advance,
    Michael

    Hi!
    I'm facing the following problem. I'd like to have a tableview where cells have a fine! black (not grey) border. The result should look like a typical Excel-Spreadsheet.
    When entering this in the css Stylesheet:
    .table-view {
        -fx-background-color: white;
        -fx-border-color: black;
        -fx-border-width: 0.8px;
    .table-cell {
        -fx-background-color: white;
        -fx-text-fill: black;
        -fx-border-color: black;
        -fx-border-width: 0.1px;
        -fx-border-style: solid;
    The border of the tablecells get grey are still are to width. How could I get my excel-like grid? When increading changing the width (i.e. to 0.5) the line gets "more black") but unfortunately also too wide.
    Thanks in advance,
    Michael

  • CSS Class for Table Cell Text

    When we were using messageStlyedText in a table region, it was shriking multiple whitespaces to a single whitespace. To solve the problem we are planning to use "rawText" with <pre> tag. But we are not able to specify the default CSS class for a table cell text. Can you please let us know the CSS class to use so that even if we use rawText UI(font, size etc) is similar to adjacent messageStlyedText columns ?
    Note: We are not using formattedText because it is not allowing to add prompt.

    Please try using CSS class OraTableCellText
    Thanks
    Abhay

  • BSP HTMLB TABLE - BORDERS FOR EMPTY CELLS

    Hello Colleagues, I'm new to BSP HTMLB, maybe someone could help me.
    I’m taking data from a DB table through select and there are a lot empty cells.
    The layout looks like:
    <htmlb:tableViewColumn columnName="PK_Terms"
    <%--wrapping="true"--%>
    width="50"
    horizontalAlignment = "center"
    verticalAlignment = "middle"
    fixedColumn="true">
    </htmlb:tableViewColumn>
    THE BORDER does not APPEAR in empty cells (the table looks horrible), how can I make it appear?

    Hi,
    If the cell is initial pass the   then it will shows the border like when the data is not initial.
    i have got this in my requirement.
    if it is not shows the any cell pass <border=1>
    Regards,
    Sri..

  • JTable - different editor for each cell?

    I have a JTable where two columns have combo box editors. When the user makes a selection in one combo box, the other combo box's options must change, as its allowable options depend on selection in the other combo box.
    So in short, I need a way of changing the combo box options for ONLY a specific cell, NOT the entire column. I currently only know how to do this for a whole column:
    // first put stuff in myComboBox, and then...
    myJTable.getColumnModel().getColumn().setCellEditor( new DefaultCellEditor( myComboBox ) );
    Is there any way to change the values in the combo box of a specific cell, rather than the entire column?
    I apologize if this is a newbish question... I am fairly new to Swing, but I didn't see anything addressing this in the documentation.
    -Vern

    The solution is like the one I gave you in one of
    your previous postings. In that posting you wanted a
    renderer for a specific cell. In this posting you
    want a editor for a specific cell. The solution is
    the same, only the method name changes.Okay, thanks. Sorry if it seems like I'm a slow learner. ;-)
    -Vern

  • Can I force Straddle for table cells in the EDD ?

    This is a question for the techies:
    In my structured EDD, I have created hazard statements according to the ANSI Z535.6 standard, using a table format - with the table heading showing the hazard category (notice, caution, warning, danger) and the rows showing the individual messages. In the individual messages I have an icon to the left and the message text next to it. Visually, it is better to separate the two cells with a thin line. But in the header there is no icon to the left and I would like to remove the thin line. Yes, I am a perfectionist, I know
    Here is what it looks like now:
    As far as I can tell, there is no way to tell Frame to suppress the column separator line in the heading without also removing it in the body rows. And if I do remove the line, there is still a thin white line visible, as the heading cells are filled with an image covering its entire area (but that image does not cross over the invisible line, at least not in the PDF). Another option would be to use straddle on the heading cells, but I need to be able to do everything from the structured EDD and paragraph plus table formats. Is there a way to do this ?
    Thanks in advance
    Jang

    Hi Michael,
    Oh, well. I had already figured out that this is not an option. I did remove the line between the rows, as it does not add any thing to the clarity of the message panels in my hazard statement table. But FM cannot handle two adjacent cells with graphic frames without adding a single hairline between them, even if I told the program that the border should be None. Something about the importance of frames for FM, I guess. I have only been able to remove the extra unwanted and uncalled-for hairline by straddling the cells (manually). Of course I will have to adapt the EDD to allow straddled cells in the header, but that is peanuts compared to the stuff I have been doing to make this design work in the first place.
    As I will have to create a small script to perform a series of necessary steps before a book can be published, and my hazard statement tables all have the exact same small problem, I will probably include a script that goes through the whole book and applies a straddle to any cells in the heading row of any hazard table. Being a perfectionist, writing that script before handing my stuff over to my customer will make me happier than not doing it and saving some time by delivering a solution that does not make me perfectly happy.
    When all the hard work for my current projects is done, I will try to publish an article on how to implement ANSI Z535 compliant hazard statements in structured FM documents. Might be useful for others, too. I will show you my solution at the tcworld fair, if you have some time for that.
    Ciao
    Jang

  • Background Image repeating for table cells

    I am trying to put different images as the background to all
    the cells in a table, so I can put text over the top of them, but I
    cant have an image without it repeating. Ive tried going into the
    code and adding background-image: "no-repeat" but that hasn't
    worked. I know nothing of CSS and it seems really confusing - so if
    this is the answer please give me CSS for dummies instructions.
    Layers drive me bonkers as no 2 browsers display them in the same
    place.
    URL is:
    http://www.visionsportsmedia.com/BillyTestSite/test
    At the moment only cell one is a background image, the rest
    are images inserted normally.
    Hope you can help.
    Thanks.

    Your question reflects the confusing mess your life will be
    if you persist
    with web authoring without taking the time to learn some HTML
    and CSS.
    You have -
    <th height="351" colspan="6" "scope="col">
    Note the extra doublequote just before 'scope'.
    Also note that your preloads (look at the body tag) as well
    as your image
    swaps (look elsewhere - everywhere you see 'file:///') are
    all broken -
    pointing to files on your hard drive. Finally, you might want
    to just think
    about making a page where there is no readable content
    (everything here is
    in images). It will get a zero search engine ranking....
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "little bob" <[email protected]> wrote in
    message
    news:gqo8jh$ejo$[email protected]..
    >I am trying to put different images as the background to
    all the cells in a
    > table, so I can put text over the top of them, but I
    cant have an image
    > without
    > it repeating. Ive tried going into the code and adding
    background-image:
    > "no-repeat" but that hasn't worked. I know nothing of
    CSS and it seems
    > really
    > confusing - so if this is the answer please give me CSS
    for dummies
    > instructions. Layers drive me bonkers as no 2 browsers
    display them in the
    > same
    > place.
    >
    > URL is:
    http://www.visionsportsmedia.com/BillyTestSite/test
    >
    > At the moment only cell one is a background image, the
    rest are images
    > inserted normally.
    >
    > Hope you can help.
    >
    > Thanks.
    >

  • Conditional Formatting - change color for matching cell

    I have two sheets, Sheet1 and Sheet2.
    Sheet1 contains the following data:
    abc
    def
    ghi
    jkl
    mno
    pqr
    stu
    vwx
    yz
    Sheet2 contains the following:
    abc
    ghi
    jkl
    mno
    pqr
    yz
    I want to apply conditional formatting in Sheet1 for matches in Sheet2, so that for each match, the cell's fill color is changed to, say green.
    I select the entire range in Sheet1 and as a New Formatting Rule, choose Cell Value equal to = Sheet2!$A$2:$A$6
    However, this throws the following error:
    "This type of reference cannot be used in a Conditional Formatting formula.
    Change the reference to a single cell, or use the reference with a worksheet function, such as =SUM(A1:E5)"
    Any help here is greatly appreciated. Thanks.

    Use the formula:
    =ISNUMBER(MATCH(A1,Sheet2!$A$1:$A$6,0))

  • Tooltip for table cell.

    Hi all
    I have a report region (the source is a query). There is lot of texts in this report region so for pretty display I am just showing the first few words for the row and column combination (i,j) and what I am looking for is the tooltip so when the user puts the mouse over a particular cell, full text of (i,j) is displayed.
    Is it possible?
    prashant.

    Thanks ATD, but are you sure its "&quot;" . Because I am getting this error
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00904: """: invalid identifier
    I tried selection generic coulmns, its giving this error
    failed to parse SQL query:
    ORA-00904: """: invalid identifier
    Then I tried '&quot;' , I dont get correct result, the result seems to be broken .
    I think its just a matter of syntax. Could you double check it for me ?
    Thanks prashant

  • Can I change the border style for normal cell?

    Im using Numbers on ipad2. As I say, Im wondering if I can change border style such as its width and colour for ordinary cells which is not a incerted media.
    As I know, Numbers only allows the position of borders for normal cells,,, anyone help me?

    You only get that when you have two or more consecutive messages. Try to avoid that is one option.
    You can change the icon if you want. Create another icon, call it stop.ico and put it in the icons directory (as indicated by UI_ICON). However, if you have a STOP alert, the icon changes for that alert too.
    Note: this is for Developer 6i. In 9i you cannot use ico files. Use gif files instead and put the image in the image jar file (found in OH/forms90/java directory). Since you see a big X, I believe you are using 6i.

Maybe you are looking for