Setting borders for JTable cells

How can i create custom / user defined borders for cells in JTable (swing).I need to have borders like only top/bottom,left/right borders for cells. I came to know that it could be possible with paintBorder() method of AbstractBorder interface. But i need a sample code of how it has been done.
Thanks & Regards
M.Shanthakumari

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

  • MouseListener for JTable cells using html

    Hello,
    I'm trying to write a MouseListener that determines whether the cursor is positioned over a certain string within a JTable cell. The cell contains an html string to allow for some formatting.
    For instance, the table data for a certain cell could be "<html><b>SomeBoldText</b>moreText<html>". I would like to detect when a mouse click occurs on the bold text.
    My current solution is to create the glyph vector corresponding to the cell content stripped of all html tags and then check if the cursor position is within one of the glyphs that form the string. However, that obviously doesn't take into account the formatting done by html, so its not working very well.
    Any suggestions?

    the only way you could possibly do this, if you used JEditorPane as a renderer. even then i'm not sure.

  • 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

  • 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.

  • 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

  • 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..

  • GridBagLayout - Question about Creating Borders for Cells

    Hello Everyone,
    I am implementing a table-like design using a Grid Bag Layout and I do not wish to use a J Table. Since a grid bag layout utilizes cells (rows and columns) to create its' design, I was wondering if any of you knew of a way to create borders for the cells inside of a Grid Bag Layout.
    The reason I ask is because, lets say for instance cell (1, 0) may occupy a single J Label. I can easily create a border for this particular cell or label, by calling label.setBorder(). However, what if a single cell occupied two JLabels and they were sort of strangely aligned. I wouldn't be able to call setBorder on the labels anymore because that will just create two separate sets of borders. What I want to do is create a border for that particular cell.
    The final result that I want it to look like is almost identical to a J Table where all the rows and columns have separating lines between all the cells. Something similar to this...
    http://www.wwffinc.com/other-images/table1-693771.jpg
    Thanks in advance!
    Brian

    However, what if a single cell occupied two JLabels and they were sort of strangely aligned. I wouldn't be able to call setBorder on the labels anymore because that will just create two separate sets of bordersThen create a panel and add the two labels to the panel. Then add the border to the panel.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

  • Update JTable cells via setValueAt

    Hello all,
    I'm trying to implement a setValueAt method using an arrayList.....no success.What listeners should I have set up(For JTable or my table model)? I am new at this and I'm trying to update the JTable cells after a query from some db. Could anyone help?
    When trying to change the a value in the table I get these errors:
    "Exception occurred during event dispatching:
    java.lang.ClassCastException: java.lang.String
    at CachingResultSetTableModel.getValueAt(CachingResultSetTableModel.java:37)
    at javax.swing.JTable.getValueAt(JTable.java:1711)
    at javax.swing.JTable.prepareRenderer(JTable.java:3530)"
    public void setValueAt(Object avalue, int r, int c){
    if(r < cache.size()){
    row[c] = (Object[])cache.set(r, avalue);
    fireTableCellUpdated(r, c);
    }//setValueAt
    *********For reference here's the getValueAt method*************************
    public Object getValueAt(int r, int c){
    if(r < cache.size()){
    row = (Object[])cache.get(r);
    return row[c];
    else
    return null;
    }//getValueAt

    I would think that everone who starts off with JTable will have a couple of concept problems. I am also going thru this learnig curve. It looks to me ( the blind leading the blind etc) like your basic table has strange data in it. The problem is occuring when the JTable is trying to setup the data from the table model.
    I don't think its anything to do with setValueAt.
    I kept going back to TableMap, TableSorter and JDBCAdaptor examples and copying the code from them to come right.> I debug by putting a System.out .... in all the methods until I get to where the code is giving trouble.
    Good luck [email protected]
    Hello all,
    >
    I'm trying to implement a setValueAt method using an
    arrayList.....no success.What listeners should I have
    set up(For JTable or my table model)? I am new at
    this and I'm trying to update the JTable cells after a
    query from some db. Could anyone help?
    When trying to change the a value in the table I get
    these errors:
    "Exception occurred during event dispatching:
    java.lang.ClassCastException: java.lang.String
    at
    CachingResultSetTableModel.getValueAt(CachingResultSetT
    bIleModel.java:37)
    at javax.swing.JTable.getValueAt(JTable.java:1711)
    at
    javax.swing.JTable.prepareRenderer(JTable.java:3530)"
    public void setValueAt(Object avalue, int r, int c){
    if(r < cache.size()){
    row[c] = (Object[])cache.set(r, avalue);
    fireTableCellUpdated(r, c);
    }//setValueAt
    *********For reference here's the getValueAt
    method*************************
    public Object getValueAt(int r, int c){
    if(r < cache.size()){
    row = (Object[])cache.get(r);
    return row[c];
    else
    return null;
    }//getValueAt

  • How to display cusomized custom tooltip(jwindow)  in jtable cell position

    Hi,
    i am trying to display custom tooltip for jtable cell. i created custom tooltip(jwindow) and on mouseover of jtable cell i am trying to display the custom tooltip.
    But it is not display the position of jtable cell. How to display the exact position of jtable cell
    please help me on this.

    Did you read the posting directly below yours which was also about a custom tool tip?
    JScrollableToolTip is buggy
    The code presented there shows the tool tip in the proper location.
    For more help create a [url http://sscce.org]SSCCE, that demonstrates the incorrect behaviour.
    Don't forget to read the "Welcome to the new home" posting at the start of the forum to learn how to use the "code tags" so posted code is formatted and readable.

  • Border for Excel Cells generated using HTML

    Hi,
    I am generating html at server side and writing the content with
    content type application/xls, all the generated data downloads to
    me in excel sheet. Here in this excel document, I dont have borders
    for the cell where i dont have the data. But for the cells, where data
    is placed, cell borders are available. How do i make the whole excel sheet
    cells as bordered.
    Thanks in advance.
    Regards,
    Rizwan.

    If I have table border="1" they show up. I want
    borders even in other parts of the excel sheet where
    table is not there. Is it possible for that to get
    the borders in entire excel sheet where data is
    present and even if data is not present?IIRC, it would not be possible unless you paint all those borders on the HTML page. An alternate way is to generate the Excel sheet using Jakarta POI, but that would only make your work tougher.

  • 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.

  • JTable, cells lost focus

    How can I get or listen to event when my cell lost focus ??

    The correct answer is to... well, that should be saved for the Swing forum. or alternatively, its in the text for THE FIRST google result for "jtable cell listener".

  • How to set a cell editable at runtime for jtable

    Hi evry body
    i need to set a cell as editable during runtime and set some value for the cell and make it non editable after setting value
    how can i do it? urgent help appreciated
    regards
    anil

    You could override the methods isCellEditable(...) and setValueAt(...) in your JTable's TableModel to get the effect desired
    // Assuming that each element of the array will be false initially
    boolean[][] valueSet = new boolean[noRows][noCols];
    public boolean isCellEditable(int row, int col) {
      return !valueSet[row][col];
    public void setValueAt(Object obj, int row, int col) {
      super.setValueAt(obj, row, col);
      valueSet[row][col] = true;
    }

  • Setting color for cells in a particular column of a jtable

    Hi, I know how to set the color for a cell in a column if the cell contains an Integer object and if I have default Integers already in the JTable when I begin. However I want the JTable to look blank at the beginning. As I can't make an Integer object invisible on the JTable I need to specify the colum in which I want the cells to change color in. I want to specify the column some how and then when the table later has Integers in it i can do a comparison to decide whether i want to change the color or not. Does anyone know how I will do this.
    Please HELP.

    1) You need to set the tooptip text on the renderer for the column (yourTable.getColumnModel().getColumn(...).getHeaderRenderer()).
    2) The header is a separate component to the table. When you add a table to a scroll pane it automatically adds the header to the scroll pane too. You can get the component (yourTable.getTableHeader()) and add it to your own container if you wish.

  • Work with JTable cell (check input, set text color)

    I have a JTable with data
    The task is:
    User inputs some data into cell
    I want to check his input string for equatily with other values in column
    For example, I have these values in column:
    1.example
    2.exercise
    3.execute
    User inputs word "execution" in the same column
    until user inputs "executi" his input string should be red.
    What event I have to listen to if I want to get user input string?
    Also a question:
    Is there any opportunity to work with cell row (copy it to another JTable) ?
    Message was edited by:
    Holod

    i think you should use cell editor as textfield (although that is default for jtable) and then implements document listener and set text color in insert update method.
    try this out :-)

Maybe you are looking for

  • Media center will play regular dvd but not blu ray

    I have seen a few questions on this but non that assist my particular situation. When I place a regular DVD in the drive it reads the dvd and says Disc ready for playing, please press start to play..I press start and a regular DVD starts right up. If

  • Viewing Camera Metadata

    I have a D200 and a SB800 flash unit. I am trying to view metedata in regards to the setting of the SB800 external fash unit. I notice that when I import pictures from my camera I can view the fash exposure compensation of the pop up flash. I would l

  • OpenCL Problem in Mountain Lion

    Hello, I'm a user from Hong Kong and I've a huge problem about Photoshop. I've a 15" MacBook Pro (Graphic Card is 6490M) and installed Mountain Lion and Photoshop CS6. When I Check my System Info in Photoshop, it show the OpenCL is unavailable just l

  • When is Linksys/Cisco going to fix E4200 problems??

    All the problems started when I upgraded from a WRT54G (never had a problem with this router over several years) to the E4200 (v1.1.02)  a couple of months ago. No problems with any of the wired connections of course, but all my wireless 2.4 GHz co

  • HT201401 How to fix my phone

    My phone got a big problem. The key over the top of the phone which was used to lock or unlock the screen was stuck. I can.t use it to lock or unlock my screen anymore. What can I do with it?