JTable (single) graphic row background?

I'd like each row in a JTable to display a single graphic image behind the whole row - not on a cell by cell basis, one long image behind all the cells in the row - and be able to dynamically choose the image for a given row based on data in one or more of the cells in that row.
Is there a way to do this with a JTable? If so any hints would be greatly appreciated. Thanks.

ajk wrote:
I'd like each row in a JTable to display a single graphic image behind the whole row - not on a cell by cell basis, one long image behind all the cells in the row - and be able to dynamically choose the image for a given row based on data in one or more of the cells in that row.
Is there a way to do this with a JTable? If so any hints would be greatly appreciated. Thanks.Interesting requirement - and satisfying for me that SwingX has all the basic building blocks ready, just a small amount of custom application code needed :-)
- implement a custom Painter which paints part of an image based on a settable property
- implement custom HighlightPredicates to decide which rows to highlight
- implement a custom PainterHighlighter configured with both: if the predicate decides that it should highlight, it will set the painter's subImage area and apply it to the renderer
- add the highlighter to your table
below are a couple of snippets: they highlight a table with interleaving two images, using the one ore other content-based custom predicates. Out in the wild, the logic would be slightly more involved, I guess :-)
Enjoy!
Jeanette
private void configureTable(JXTable table) {
        HighlightPredicate rocketPredicate = new HighlightPredicate() {
            @Override
            public boolean isHighlighted(Component renderer,
                    ComponentAdapter adapter) {
                Integer value = (Integer) adapter.getValue(3);
                return value.intValue() < 50;
        HighlightPredicate moonPredicate = new NotHighlightPredicate(rocketPredicate);
        table.setHighlighters(
                new SubImagePainterHighlighter(rocketPredicate,
                        new SubImagePainter(rocketImage)) ,
                new SubImagePainterHighlighter(moonPredicate,
                        new SubImagePainter(moonImage))
// the custom Highlighter
public static class SubImagePainterHighlighter extends PainterHighlighter {
    public SubImagePainterHighlighter(HighlightPredicate predicate, SubImagePainter painter) {
        super(predicate, painter);
    @Override
    protected Component doHighlight(Component component,
            ComponentAdapter adapter) {
        Rectangle cellRect = getCellBounds(adapter);
        ((SubImagePainter) getPainter()).setImageClip(cellRect);
        return super.doHighlight(component, adapter);
    private Rectangle getCellBounds(ComponentAdapter adapter) {
        // PENDING JW: add method to adapter
        JXTable table = (JXTable) adapter.getComponent();
        Rectangle cellRect = table.getCellRect(adapter.row,
                adapter.column, false);
        return cellRect;
// the custom painter (very crude of course)
public static class SubImagePainter extends AbstractPainter {
    BufferedImage image;
    Rectangle imageClip;
    public SubImagePainter(BufferedImage image) {
        super(false);
        this.image = image;
    public void setImageClip(Rectangle imageClip) {
        this.imageClip = imageClip;
    @Override
    protected void doPaint(Graphics2D g, Object object, int width,
            int height) {
        if ((imageClip == null) || (imageClip.width <= 0) || (imageClip.height <= 0)) return;
        if (imageClip.x + width >= image.getWidth()) return;
        if (imageClip.y + height >= image.getWidth()) return;
        Image subImage = image.getSubimage(
                imageClip.x, imageClip.y,
                width, height);
        g.drawImage(subImage, 0, 0, width, height, null);
}

Similar Messages

  • JTable row background change - based on EXTERNAL event

    Greetings folks!
    I'm hoping for some help with a JTable issue. Here's the scenario:
    The app is a point of sale application. The user scans or manually adds an item to the order, which causes a row to appear in the JTable displaying description, price, quantity, etc. The user can then right click a row on the JTable and select an option from the popup menu. If the user selects one of the options, I want to be able to change the background color on that row.
    EVERYTHING I've seen online and researching is based on adding a custom renderer to the jtable which changes the background based on the data in the row. In my case there isn't anything in the row which changes... hence the point of changing the color.
    What I'm looking for is a method which will let me change the background of row x. I'm guessing there isn't a way. I'm hoping someone has a suggestion.
    Thanks in advance,
    John E.
    PS: I'm fairly new to java and working with inherited code, so please no 'you need to redesign the world' type answers unless there's an easier way. :)

    In my case there isn't anything in the row which changesThen how is the table going to know what color to paint the row? Remember painting the row is a dynamic process. You can't just paint it once. You need the ability to repaint the row if for example the table is scrolled and the row is now longer present. Then when the table scrolls again and the row is present you need to be able to repaint the row in your specified color. This means you need some way to tell the table what color the row should be. Which means you need to keep that information somewhere.
    One way to do this is to store the data in the TableModel that indicates that this row should be painted a "different" color. Then your situation is like the examples you have found. You now have some data you can test. This column does not need to be visible in the table since you can remove the TableColumn from the TableColumnModel so the column is not painted.
    Here is a simple posting that shows a better approach to painting row backgrounds withouth using a renderer:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • View a single table-row as multiple rows in a GridControl

    Hi,
    is it possible to distribute the entries of a single row of a table/RowSetInfo over multiple lines of a GridControl?
    I've seen an example on the Internet (http://www2.gol.com/users/tame/swing/examples/JTableExamples4.html) which does this without database connection but it seems as if it's necessary to replace the default JTable, TableModel and UI by customized ones. As far as I've seen it's not possible to replace the JTable which is used by a GridControl? So is there any other way to do this? (A modification of the JTable-UI itself doesn't suffice as the JTable yields wrong row- and column-numbers on mousclick-events and therefore the components of the second row are not enabled properly).
    Thanks in advance
    null

    |I've seen an example on the Internet |(http://www2.gol.com/users/tame/swing/exampl|es/JTableExamples4.html) which does this |without database connection but it seems as |if it's necessary to replace the default |JTable, TableModel and UI by customized |ones.
    You wont be able to replace the JTable. But you can change all the attributes on the internal table which the grid uses (see getTable() method). The datamodel for the grid is impemented by oracle.dacf.control.swing.GridDataSource. You can possibly extend this class. You can also change the Table column model and the renderers used by the Table.
    |So is there any other way to do this? (A |modification of the JTable-UI itself doesn't |suffice as the JTable yields wrong row- and |column-numbers on mousclick-events and |therefore the components of the second row |are not enabled properly).
    Could you expain how the mapping between cell renderer and the table (row, col) is done in the extended JTable - which class ?.
    (http://www2.gol.com/users/tame/swing/exampl|es/JTableExamples4.html)
    null

  • Set Table Row Background image

    Hi all,
    I'd like to set a Table row background image, but I only find a way to set a background image for each column, is there any way to set an image  as background for a whole row?

    Hi Pakojones,
    Based on my test, it is not support to make the image tile in a row. The BackgroundRepeat values of tablix is Repeat, RepeatX, RepeatY, or Clip. In SSRS, just chart BackgroundRepeat can be set to Fit.
    Reference: http://technet.microsoft.com/en-us/library/dd239334.aspx
    In SSRS, we can put tablix in a rectangle, then add background image for the rectangle. We can tile the image over the whole tablix. If we want to make the image tile in a row, we can put the single row in a rectangle to work around it. In this situation,
    we have to seamless paste the tablix in the end.
    Alternatively, since the issue is by design, I recommend you that submit this suggestion at
    https://connect.microsoft.com/SQLServer/ . If the suggestion mentioned by customers for many times, the product team may consider to add the feature in the next SQL Server version. Your feedback is valuable
    for us to improve our products and increase the level of service provided.
    Regards,
    Alisa Tang 
    Alisa Tang
    TechNet Community Support

  • How to find out if JTable's selected row is visible?

    Hello there,
    Given:
    a JTable is inserted into a JScrollPane and the number of rows in the table is greater than the vieport size.
    A random row within the table gets programmatically selected.
    How to find out if the selected row is visible in a JTable visible area?
    Your help will be greatly appreciated.
    Tim

    That will make the row visible, but not answer whether it was visible
    in the first place. Try something like:
    public boolean isRowVisible( JTable table, int row ) {
        Rectangle rect = table.getBounds();
        int rowHeight = table.getRowHeight();
        int viewHeight = table.getParent().getHeight();
        int max = rect.y - viewHeight + 1;
        int rowPos = - rowHeight * row;
        return ( rect.y >= rowPos && rowPos > max );
    }assuming all rows have the same height.
    : jay

  • WorkOrderList TileView Row & Selected Row Background Color Change

    Hi,
         can we change the background color of WorkorderList TileView Row & Selected Row Background color ?. Actually i am trying to change the color of both in WorkOrderList but it not reflecting any color on my Agentry client. I used a style on Tile List View Data/Style.
    but these applied style on Rows & Selected Rows are not working in Agentry client.
    if any other alternate solution exist in Agentry, please guide me.
    i am using following...
      sap mobile platform-2.3.3
    Thanks & Regard
    Manish Kumar
    Tags edited by: Michael Appleby

    Hi Jason
          Yes using Image we can achieve that goal but i want to use a background color instead of Image background. Finally I used a background color on label and set the that label field on Screen. And It's showing the background color on WorkOrderList Row & Selected Row that what i wanted. But on both Row & Selected TileView Screen showing white outline that i don't want and also i could not remove the default Selected Blue Background Color.
         Please guide me how to remove white outline and default Blue Selected Background color.
    Thanks & Regard
    Manish Kumar

  • Single Sub Row Query Returns More Than 1 Row!

    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID where B.PRV_TYPE = M'
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVID PRV_NAME
    1234 PHOENIX MED
    1235 SAC MED
    1236 SAC MED
    1237 OVERLAND
    etc..
    So, as you can see the PRVID's are unique, but not the PRV_NAME's. Is this the reason why I get this error?
    I did not build the tables and have no control over what is put in them. If this is the reason for the error, is there any way to resolve this?
    For reference, here is the query. Maybe there is something wrong with this?
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')
    Edited by: user12296489 on Apr 19, 2013 10:46 AM

    Hi,
    user12296489 wrote:
    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row. Post your code. It's hard to say what you're doing wrong when I don't know what you're doing.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVIDIf b.prvid is really unique, then
    UPDATE  a
    SET     prv_name = (
                     SELECT  prv_name
                     FROM    b
                     WHERE   a.prvid     = b.prvid
    ;should work, whether the other columns are unique or not.
    (Depending on your data and your requirements, you might want to use MERGE rather than UPDATE).
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Apr 19, 2013 2:00 PM
    I see you've posted your code now:
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')Even if ps.prvid is unique, the sub-query can return more than 1 row if prv00.prv00_prv_id is not unique. When that that's the case, what do you want to happen? Include examples when you post the sample data and desired results.

  • SQL query - return single unique rows

    Hi
    If you have an employee table where employees are listed per department, using SQL, how could you return the names of the employees listed per department on a single unique row?
    Eg - select deptno, first_name from employee
    deptno first_name
    10 Jane
    20 Jack
    10 Joe
    20 Jill
    10 Jacinta
    30 John
    30 Jeffrey
    10 Jackie
    30 Jennifer
    ... etc.
    the return set of the query would look like:
    deptno first_name concat
    10 Jane Joe Jacinta Jackie ..
    20 Jack Jill ..
    30 John Jeffrey Jennifer ..
    Cheers

    Here you go:
    WITH t AS
    (SELECT 10 deptno, 'Jane' first_name FROM dual UNION
    SELECT 20 deptno, 'Jack' first_name FROM dual UNION
    SELECT 10 deptno, 'Joe' first_name FROM dual UNION
    SELECT 20 deptno, 'Jill' first_name FROM dual UNION
    SELECT 10 deptno, 'Jacinta' first_name FROM dual UNION
    SELECT 30 deptno, 'John' first_name FROM dual UNION
    SELECT 30 deptno, 'Jeffrey' first_name FROM dual UNION
    SELECT 10 deptno, 'Jackie' first_name FROM dual UNION
    SELECT 30 deptno, 'Jennifer' first_name FROM dual)
    SELECT   deptno,
             RTRIM(XMLAGG(XMLELEMENT(c, first_name||' ') ).EXTRACT ('//text()'), ' ') names
    FROM     t
    GROUP BY deptno

  • AdvancedDataGrid Row background color

    Hope someone can help, I wish to highlight an entire row or rows that match a value. I assumed the stylefunction would get me there but I have not found the style refering to the row background color.
    Any help please.
    Thank You

    The solution I found was to extend the data grid class, add override to the draw background and add a rowcolorfunction. When using item renderers you must use the style function with the alternatingItemColors so the renderer gets the color correct and not opaque.
    Thanks looking saisri2k2.

  • Row background color in dataTable control based on criteria

    It is relatively straightforward to give a pattern of color to rows in a dataTable control, for instance to alternate colors from white to gray.
    However, I have not yet figured how the row background color could be decided based on data fields associated with each row. For instance, I would like to set the row background color based on the value of a boolean attribute associated with the row, e.g. white if value is false and gray if it is true.
    Is there an easy way to do this?
    Martin

    of the text, but not the whole cell. I need to find a
    way to change the span at the row level (on the <tr>
    tag). ANy ways to do this?
    MartinThis is a question of how to let the renderer adjust its behaviour depending on the current state of the model. My renderer changes the background for the selected row by changing the style class:
            writer.startElement("tr", table);
              if (table.getRowSelector())
                   if (table.isAtSelectedRow())
                        writer.writeAttribute("class", "selectedRow", null);
    etc.(of course, to be able to do this you must write your own renderer)
    erik

  • Advanceddatagrid grouped row background color

    Hi All,
    How to create a grouped row background color in advancedatagrid eg:
    Features
    Product 1
    Product 2
    Group1
       aa
    copy
    copy
       aa
    copy
    copy
    Group 2
       bb
    copy
    copy
       bb
    copy
    copy
    Thanks,
    srinath

    The solution I found was to extend the data grid class, add override to the draw background and add a rowcolorfunction. When using item renderers you must use the style function with the alternatingItemColors so the renderer gets the color correct and not opaque.
    Thanks looking saisri2k2.

  • Can I turn a page of photos into a single graphic?

    I've got a page of photos, drop shadows etc., a bit slow to load. I know I can turn all the photos (with their related text and drop shadows) into a single graphic. But what is the maximum size (k's) I need the graphic to be so that it will still load faster than all the separate elements?
    B.

    Preview's PNG's are kinda large. Photoshop can make smaller PNG's but since PNG is not lossy, you can only affect the file size to a certain degree. I came across this site
    http://www.codinghorror.com/blog/archives/000810.html
    Which mentions a utility called PNGOUT. (at the bottom of this page)
    http://advsys.net/ken/utils.htm
    You may be able to further shrink your PNG's with that.
    UPDATE: Just found this more graphic solution.
    http://www.amake.us/software/pngcrusher/
    Message was edited by: Kyn Drake

  • Z87 XPower PCI_E2, Single Graphics Card plus Other Expansion Cards

    A bit confused on the PCI-E expansion slots...
    I seem to have read somewhere that it is preferential to place a single graphics card in PCI_E2 slot. Found a reference on a review:
    "However for those using a single graphics card MSI recommends installing it in the second PCIe slot as this slot is connected directly to the CPU, meaning there is no latency lag as it bypasses the PEX 8747 chip"
    However, the PCIe x16 Slots Bandwidth Table clearly shows only one "video card"  (any other pci-e expansion card, too?) is possible when taking advantage of PCI_E2:
                   E1    E2  E3   E5   E7
    Single:      0  x16    0     0     0
    2-Way:  x16     0    0  x16    0
    3-Way:   x8      0  x8  x16    0
    4-Way:   x8      0  x8    x8  x8
    I picked up a pci-e OCZ RevoDrive 3 x2 SSD 240GB and looking to use a N770 graphics card in PCI_E2... is this even possible? Ideally, I would choose to run the RevoDrive from PCI_E1.
    From reading the table, I get "no".
    I called MSI support, and 2 agents seemed to believe the PCIe x16 Slots Bandwidth Table only related to graphics cards ("The table below shows the correlation between the PCIe slots bandwidth and multiple
    graphics cards."). Still waiting an official response to ticket(s). I spoke with the first before I began my graphic card installation, and the second after I installed and couldn't get the RevoDrive to show in any slot when the graphic card was installed in PCI_E2.
    My experience is telling me I have a problem, and I have some decisions to make moving forward. Generally speaking:
    1. Is it possible to install a single graphics card in PCI_E2 to bypass the PEX 8747 chip and achieve x16 bandwidth, and still have another pci-e in another x8/x16 slot?
    2. What is more important for the video card: x16 bandwidth, or "latency lag as it bypasses the PEX 8747 chip"?
    3. The performance of the RevoDrive is outstanding (knock on wood... hoping I can keep this card running a long time considering the volume of drive failures experience with OCZ drives). I am considering my overall day-to-day usage and wondering if I might be better off ditching the RevoDrive or the graphic card... or (oh my, GOD!) another board....
    It is easy for me to criticize engineering for overlooking this potential design consideration, yet it is an outstanding board. I should have been more aware when I read the 0-16-0-0-0 config details on the PCIe x16 Slots Bandwidth Table and the detail on the PEX 8747 chip. Once of the major items that attracted me to the XPower was the heap of features and pci-e expandability. Yet, all the PCI-E bandwidth and slots don't do me any justice if I can't config my install to optimize my system's components.
    I would have a hard time trying to pick another to even try to replace the Z87 XPower (it would have to be Asus Z87-DELUXE).
    What would I lose or gain in keeping the RevoDrive vs the graphic card? I initially began building this system around the RevoDrive, and I can't imagine wanting to keep the system without it.
    4. What am I sacrificing/gaining in having the graphic card in PCI_E1 and the RevoDrive in PCI_E5?
    5. With two different x16 pci-e components installed, and only one of them a graphic card, does the PEX 8747 chip latency become a non-issue? Is it still preferential to keep the graphic card in PCI_E2 position?
    PSU: Corsair AX1200i
    CPU: i7-4770k
    MOBO: Z87 XPower
    VGA: MSI GTX N770 Lightning 2GB
    SSD: RevoDrive 3 x2 240GB
    RAM: Generic 1333 (special ordered Corsair Dominator 2400MHz)
    Thanks for any additional insight and clarity!

    1: connecting a single card in PCI_E2 will bypass the PLX8747 but if you use one of the other slots for something it will start to use the PLX chips again to duplicate lanes!
    2: PCI-E lanes are of very little importance as you will only see a .1 to 2FPS reduction in frame rate between x16 and x8. and less lag is similar in that regard too and will have very little noticeable difference!
    3: it should make very little difference to either component and changing board makes in the z87 family lines would make very little difference too as to get higher expandability you need that PLX chip to sub divide the lanes and create a extra 16 fake lanes to allow more then 2 way SLI or 3 way Crossfire on the Z87 boards as the CPU's only have 16 lanes total!
    4: not much! about a hundred nanoseconds of lag, maybe 1MBP/s less on the revo drive and .1 to 2 FPS less on the Graphics card...
    5: no you would need them in the E1 and E5 positions and using the PLX chips as you will have problems and both may go into x8 using only the CPU's 16 lanes total if the Graphics card is in E2 or the revo drive may not function at all as the graphics card may hog all the PCI-E lanes....

  • How to draw Alternative Row Background in TileList?

    HI All,
    I have tried to draw Alternative Row Background by using drawRowBackground().
    But there is not parameter to pass the value.
    How to draw alternative row background in tilelist?

    Does Rado's following blog entry help: http://adf-rk.blogspot.com/2007/01/adf-oracle-form-like-overflow-in-adf.html

  • JTable: re-select rows

    I have a JTable with many rows and X number of cols.
    The user selects some rows.
    I call getSelectedRows() to find out what rows have been selected.
    I do some stuff and sort the rows. This loses the selection and the selected rows can be different numbers now.
    How can I re-select the right rows....there is no setRowSelection(Object o).

    You'll need to figure out how to map from original to new row indices. Then use javax.swing.JTable.addRowSelectionInterval(int, int) to reselect. The Java tutorial provides a class called TableSorter that handles sorting and maintains an index map.

Maybe you are looking for

  • Get all groups from an AD Server

    Hi everyone, I'm trying to get all groups from and AD server. Here's how I'm doing it: DirContext ctx = new InitialDirContext( (Hashtable<String,String>) env);           Name n2 = new CompositeName().add(groupsContainer);           NamingEnumeration<

  • After upgrading to Mountain Lion OSX 10.8.2, my HP Photosmart printer is not working

    My HP Photosmart 380 series printer is no longer working since upgrading to the Mountain Lion OSX 10.8.2. Need to know where to find installation software and updates so that it shows as an available and working photo printer. Also need how to inform

  • Anyone familiar with Freeverse's Sound Studio application used with iTunes?

    I have been using Freeverse Software's Sound Studio application for the last year, which allows me to record workshops I lead, in AAC format, and I've always been able to drag the files into iTunes and play or burn them. Since upgrading to Leopard (a

  • Z1 - can't detect the SD card

    Hello, I just received a Z1 (6903) with the latest Android OS update (5.0.2) Update 14.5.A.0.270 and It doesn't detect any SD card when I insert them. I tried 3 different card - 2GB, 8GB and 16GB (micro SD and micro SDHC) - Fat32 and even exFat forma

  • How do you change permissions on Lightroom 4 web export?

    I am having issues with my web module on Lightroom 4 (Mac OS 10.9.5). "an unknown error occurred" while trying to upload to my FTP (no changes in my FTP). Bandaid fix was to export to local folder and upload via Filezilla. However, now that is no lon