Setting the color (or other properties) of a single table row

Say I have a data model backing a table view, with a field like e.g. "isDisabled". And for every item where this field is true, I want to set the text color of the table row where the item is displayed to grey, or something otherwise suitable.
It doens't seem that it is possible to use the row factory for this. Do I have to set a cell factory for each cell and set the text color of the cell individually?

I spent a few minutes today extending DataFX (http://www.javafxdata.org) to support styling entire TableView rows via CSS. It's now going to take me considerably longer to describe the API I just provided in DataFX :-)
So, to start with, this is just a proof of concept. I look forward to you using it and giving me feedback. What you are going to need to do is create a custom TableView row factory, like so:
tableView.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
    @Override public TableRow<Person> call(TableView<Person> p) {
        final CSSTableRow rowCell = new CSSTableRow() {
            @Override public void getCssState(List s) {
                super.getCssState(s);
                s.add(getIndex() % 2 == 0 ? "even" : "odd");
        rowCell.getStyleClass().add("alternate-style-test");
        return rowCell;
});Basically what I'm doing here is creating a new TableRow on-demand, of type CSSTableRow, which is a class provided in DataFX. I override the getCssState method and add strings to the list that represent the state of that row. In this example, I'm basically using the index value of the row to alternate between "even" and "odd" states. In your case, you'll probably do something like
tableView.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
    @Override public TableRow<Person> call(TableView<Person> p) {
        final CSSTableRow rowCell = new CSSTableRow() {
            @Override public void getCssState(List s) {
                super.getCssState(s);
                if (getItem() != null && getItem().isActive()) s.add("active");
        rowCell.getStyleClass().add("active-table-row");
        return rowCell;
});The other thing to note is that every row is given a style class. This is how you target them from CSS. So, moving on to CSS, here is the test CSS I wrote for my alternating row colour test:
.alternate-style-test:even {
    -fx-text-fill: green;
.alternate-style-test:odd {
    -fx-text-fill: red;
}Without doubt you can quite easily connect the dots (and easily appreciate that I am not a designer) :-) All you need to do now is bring in your custom CSS, and hopefully you should get the result you expect.
If you have any problems, my contact details are on the DataFX website here: http://www.javafxdata.org
I'll be uploading this new API shortly, in what will be version 0.0.4.
-- Jonathan

Similar Messages

  • Flex 4:  Change the color (or other properties) of the Control Bar

    Can the control bar color and other properties be changed?
    Thank you.

    look for
    <!-- layer 2: control bar fill -->
                        <s:Rect left="1" right="1" top="2" bottom="1">
                            <s:fill>
                                <s:LinearGradient rotation="90">
                                    <s:GradientEntry color="0x000000" />
                                    <s:GradientEntry color="0x005500" />
                                </s:LinearGradient>
                            </s:fill>
                        </s:Rect>
    in the style generated ..you can change the fill to any of the types like solidColor, all gradients, in addition, you can add stroke element to this rect, thats all I know, if you know any other properties that can be added here, you can let me know.

  • Setting the color (or background color) of a substring

    Is it possible to set the color of a substring. For example:  If I had the string "Steve is stuck and needs help" and I wanted to change it to become "Steve is stuck and needs help".
    At present I am trying to modify the text inside of a String Indicator, but am open to suggestions.
    I have been reading the LV help and it seems to suggest that you can do this using the Text.SelStart and Text.SelEnd properties, but I can't get over that last hurdle that actually updates the string.
    Regards
    Steve
    https://decibel.ni.com/content/blogs/DailyCLAD
    Solved!
    Go to Solution.

    So close.
    Thanks All
    https://decibel.ni.com/content/blogs/DailyCLAD

  • Dynamically setting the color of the title in a Panel

    Hello, I know I can set the color & font of the title in a Panel using the titleStyleName in a stylesheet.  How can I dynamically change the color though?  I have a component:
             <mx:Panel id="myPanel"borderColor="{this.color1}" />
    where this.color1 is a value that changes dynamically, and thus changes the border color.  How do I do this for the color of the text in the title?

    Hi,
    Try this
    var css:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".myPanelTitle");
    css.setStyle("color",0x00FF00);

  • How to set the color to the particular row in a report

    Hi
    I have a report in which I have an edit link(I changed the id as edit link)..When I click that link, all the details(the whole row details) will be appearing on the items nearer to the report to save the changes....
    I want to set the color for the particular row when a link is clicked and the color should not be changed until I save the changes in items...After saving the changes, the report should come in the normal color...this is my requirement..i refered many forums regarding this...But could not find solution....If anyone knows,please help me...
    Fazila

    Here is how I would implement
    Create renderer
    Add SkinnableContainer element and create a skin for this container namely SkinnableContainerSkin
    find the fill section in the skin
    add bitmap fill to the fill section and give the source of the image which you are planning to use(Hopefully this is a direct way of doing, may be you need to hack this a little to get it to work)
    I've never tried this, but should help you give some idea.

  • How to set the color scale so that we can get same color for same intensity of color in various runs

    Hi
    I am trying to get the color pattern of mashed potato trays and diferent trays has different color intensity but if IF i am chsooing rainbow plateu it's giveing red color for dark region of each tray but two tray has different intensity of dark color. Can you suugest me how should I set the color scale so that I can distinguish which tray has higher degree of intensity of darkness.
    I will be obliged to get the suggestions

    Hello,
    Thank you for contacting National Instruments. I just have a few questions for you to help us clarify your application:
    What API, such as LabVIEW or C, are you programming your application in?
    Are you using Vision, and if so what specific functions are you currently using?
    Is the lighting consistent and just the color of the trays changing?
    How are you displaying the image in your program? Are you using an Image Display control?/li>
    Depending on what functions you have available, then we may be able to work on finding a way to distinguish between the different intensities. If you could provide a little information to your application based on these questions then will be able to better understand and help you with your app
    lication.
    Regards,
    Michael
    Applications Engineer
    National Instruments

  • Upon Loading of page, Setting the Top and Left properties of a TextField

    Hello again,
    I would just like to ask for suggestions on how to successfully set the top and left properties of a Textfield as soon as the page is loaded.
    Thru Giri's help, I was able to do this with the push of a button. What I would need to do right now is to set it as soon as the page is loaded.
    Thanks!

    Hi Jim,
    It is not clear what you are trying to do here. If you want to set the top and left properties of a component when the page is loaded all you have to do is set it at design time itself. If the properties need to be set the second time the page loads then the code can be used in the event handler which submits the page.
    It would help if you could explain the use case for setting the properties of a component when the page is loaded.
    Cheers
    Giri

  • Setting the Top and Left properties during runtime, depending on...

    hi guys,
    it's me again with the same question, but same scenario...
    but probably with a bit clearer detail now...
    actually, what i wanna do is that although i have set the top and left properties at design time, as soon as the page opens i wanna be able to do the following:
    if ( userlevel == 1 ) {
    textfield1.setStyle("top: 100...");
    } else if ( userlevel == 2 ) {
    textfield1.setStyle("top: 500...");
    thanks for your time =)

    The style properties CAN be set in the prerender call. Unfortunately, the requirement is that the component (text field in your case) has to have an unset property in the Design->properties window. (Or in the actual jsp code, which should be identical).
    My main issue with this is SJC2's handling of this in the visual window. If i want to have a lot of components that are designed before run-time but placed during run-time, they all are a mess on the screen. I wish there was another property (in the properties window) that would be a checkbox, like "Use static layout". I, probably like others, am using a layout panel (grid) that has several other components in there. I want to be able to move this set of components at run-time, but to do so, I need to unset the layout panel's style. This causes my inside components to shift to the top left of my page, making a mess in the design window.
    If any SJC developers are out there, please help! It would be great to somehow mitigate the static/dynamic properties/display issue. (Like, i want to have buttons with dynamic names (for localization), but basically, i have to have a bunch of blank buttons/text on the screen for all my pages because of the static requirement. At least, MyEclipse and others will put the id value if the text/label value is blank.
    Chris

  • Link Color not changing for Visited Pages - How do I set the Color?

    In earlier versions of Safari, the user could select the color used to display links that have already been visited. I can't find that option in Preferences anymore. Some visited links do show a different color, some don't. Is it just random? How do I set the color in Safari 4.0.4 and activate the behavior?

    HI,
    I think you change visited pages link colors using Google preferences.
    http://www.googleguide.com/preferences.html
    Carolyn

  • Can you set the color of a specific element in a JList?

    Is it possible to set the color of a single element in a JList without writing lines and lines of your own class? I know setForgroundColor exists, it just changes all element in a JList, so is there a simple way to tweak it? i am still a newbie, so re-writing swing, would be a bit of a problem for me. Any Suggestions? thanks.

    you write your own renderer, about 6-8 lines, setting the color determined by an
    if/else statement - note: you must set the color in both if and else
    search the forums for
    "implements ListCellRenderer"
    and you should find plenty of examples
    if you just want the selected element a different color, you can do this with
    UIManager.put("List.selectionBackground", new javax.swing.plaf.ColorUIResource(Color.YELLOW));
    but you must do this before you create the JList, and it will affect all JLists in your program.

  • Can u tell me how to set the color of the button and its border

    hi to all,can u tell me how to set the color of the button and its border

    There are sample code on the java.sun.com
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/index.html
    try this web page ... There are lots of examples... Good luck ... "Gan en "

  • Setting the color of a disabled checkbox...

    Hi,
    how do I set the color of a (disabled) JCheckBox because the following code does not work for me:
    jCheckBox1.setForeground(Color.BLACK);The background is that I don't want to have the checkbox in this grey (disabled) style, instead it should look like a "normal" checkbox (but disabled).
    Any ideas?
    Best regards
    - Stephan

    WindowsLookAndFeel uses native APIs to draw most of the controls. So, a disabled checkbox under Windows LAF will use the same API as the native disabled checkbox. You can install a custom JXLayer on that checkbox to prevent all the events from being passed to it - not the cleanest solution, but it will get you there (and make your users annoyed that they can't click on that checkbox).

  • Setting the color on selected Tab

    Hi,
    I can't seem to figure out how to set the color on the
    selected tab in a JTabbedPane. I've added a
    ChangeListener but when I try to use it, it only
    changes the color after the tab has been selected.
    I want to change it while it is selected.
    How can I do this?

    Maybe this helps:
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    Kurta

  • Setting the color of 3D EM Structures

    i have no issues setting the color i like for the 2D layer drawings. 
    and they are also correct on the 3D of the schematic layout
    however my problem is in setting the color in 3D layer for EM structures. They seem to be different.
    I tried setting the color of my material definitions (topmetal) under the material definitions tab of the STACKUP.
    but the color does not correctly translate in the 3D EM structure.
    please advise.

    i got it correctly setting the color of the 2D and 3D for EM structures by following your suggestion in setting the COLOR KEY. that's new to me. thanks
    but my major problem is still unsolved where the color settings of my 2D/3D schematic layouts is different from 2D/3D EM structure layout. I always set the color in the LPF file. for my case for example, my topmetal is defined in lpf as RED. but then when i draw shapes in 2D EM structure, the color for this topmetal layer becomes BLUE...quite lost on this because there's only 1 way to set the color in LPF under "General, Drawing layer 2d"...

  • Setting the color of the window title in Forms 6i

    How does one control or set the color of the title of the MDI and module windows
    gordon
    [email protected]

    Gordon, I'm pretty sure this is actually outside the realms of Forms since the Window Manager is controlled by the O/S and so the only way you can set this is via the PC desktop (there is nothing exposed in Set_Window_Property that can do this).
    Hope this helps.
    Regards
    Grant Ronald
    Forms Product Management

Maybe you are looking for

  • Cannot edit text in Mac Mail

    Just updated to Mavericks (10.9.4) on my MacBook Pro, and among many other annoying issues, when I type out an email I cannot easily edit the text once typed. For instance if I misspell a word, I cannot click on it with my cursor to edit; I have to c

  • Loading an external swf into my parent swf?

    Does anyone know how I can load an external .swf file into my parent file? I have tried to use loader actionscript but think I am using the incorrect script or putting it in the wrong place? If anyone can tell me the script and where to/how to use it

  • Possible to receive Korean e-mails?

    I received an email written in korean on my gmail account (that is paired with my iPhone), but on the phone the korean text does not show, instead, it shows all the "weird" symbols (usually happens when the computer/iphone does not support multiple l

  • Column values as Page Header

    Hi All, I want to display some column values like Company_Name, Company_Address etc in the Page Header of the report. I am fetching these values from table in the query of my report. Can somebody tell me how I can do that? I tried placing a repeating

  • CS4 Mac Can I move a row in a table?

    I've made a table, but I now would like to move row 7 to occupy the position of row 2, thus pushing the others down so that the previous row two would now be row 3.  In Excel, I would select the row and then click and hold the selected row with the m