How to center icon node in TableCell

Hello,
I created a table as an example and surprisingly got it (almost) right the second time. However, I am having trouble centering my icon column.
This is a table of colors. My model class is the ColorBlob (see code below)
package tablewithicon;
import javafx.scene.paint.Color;
public class ColorBlob {
   public ColorBlob(String name, Color color)  {
      this.name = name;
      this.color = color;
   private String name;
   public String getName()   { return name; }
   private Color color;
   public Color getColor() { return color; }
   @Override
   public String toString() {
      return "ColorBlob{" + "name=" + name + ", color=" + color + '}';
I made a ColorDisplay class to hold the code that builds the table. This class holds the TableCell implementation that I think I need for the icon (which is really just a rectangle). But:
1. I cannot get the icon centered.
2. There is an extra column of nothing-ness displayed, even though I only specified 2 columns.
3. I don't understand why so many TableCell objects are being created for my one column of icons. Wouldn't 1 TableCell be enough?
Here is the code for ColorDisplay (and, after that, the framework code to pull it all together)
package tablewithicon;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.util.Callback;
public class ColorDisplay
   private TableView<ColorBlob> table = new TableView<>();
   private ObservableList<ColorBlob> colors = FXCollections
     .observableArrayList(
       new ColorBlob("Gray", Color.LIGHTGRAY),
       new ColorBlob("Red", Color.RED));
   public ColorDisplay() { fillTable(); }
   private void fillTable() {
      table.setItems(colors);
      TableColumn<ColorBlob,String> nameColumn = new TableColumn<>("Name");
      nameColumn.setCellValueFactory(
          new PropertyValueFactory<ColorBlob, String>("name"));
      nameColumn.setPrefWidth(100);
      TableColumn<ColorBlob,Color> colorColumn = new TableColumn<>("Color");
      colorColumn.setCellValueFactory(
         new PropertyValueFactory<ColorBlob, Color>("color"));
      colorColumn.setCellFactory(new ColorCellFactory());
      colorColumn.setPrefWidth(100);
      ObservableList<TableColumn<ColorBlob, ?>> columns = table.getColumns();
      columns.add(nameColumn);
      columns.add(colorColumn);
      // Why is there a 3rd empty column and how do I get rid of it?
   public static class ColorCell extends TableCell<ColorBlob, Color> {
      Rectangle rect = RectangleBuilder.create()
          .width(20)
          .height(20)
          .build();
      public ColorCell() {
         setGraphic(rect);
//       How do I get the icon in the center of the table cell?
//       I've tried the following:
         setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
//         setContentDisplay(ContentDisplay.TOP);
//         setContentDisplay(ContentDisplay.CENTER);
//         setText(null);
      @Override
      protected void updateItem(Color color, boolean empty) {
         super.updateItem(color, empty);
         rect.setVisible(!empty);
         if (!empty) {
            rect.setFill(color);
   public TableView<ColorBlob> getTable() { return table; }
   private static class ColorCellFactory
      implements Callback<TableColumn<ColorBlob, Color>,
                                    TableCell<ColorBlob, Color>> {
//      private Map<TableColumn<ColorBlob, Color>, TableCell<ColorBlob,Color>>
//             cellMap = new IdentityHashMap<>();
      @Override
      public TableCell<ColorBlob, Color> call(TableColumn<ColorBlob, Color> p) {
         return new ColorCell();
//       Why does it create so many cells?
//       I thought only one would be needed
//       but the following code causes problems.
//         TableCell<ColorBlob, Color> cell = cellMap.get(p);
//         if (cell == null)
//            System.out.println("HEY: " + p);
//            cell = new ColorCell();
//            cellMap.put(p, cell);
//         else
//            System.out.println("ALREADY THERE!");
//         return cell;
Main class:
package tablewithicon;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TableWithIcon extends Application
   @Override
   public void start(Stage primaryStage)
      ColorDisplay colorDisplay = new ColorDisplay();
      StackPane root = new StackPane();
      root.getChildren().add(colorDisplay.getTable());
      Scene scene = new Scene(root, 300, 250);
      primaryStage.setTitle("Hello World!");
      primaryStage.setScene(scene);
      primaryStage.show();
   public static void main(String[] args)
      launch(args);
}Again, my questions are:
1. How do I center the icon in my "Color" column?
2. How do I get rid of the extra blank column?
3. Why is one TableCell object not enough to populate the "Color" column? (optional)
Thank you so much for taking the time to read this.
Edited by: jaylogan on Mar 4, 2013 12:56 AM

Thank you, shakir!
Based on your answer, I used the width property of the TableCell to center my icon. I still don't know why so many of them are created but, unless there is a better way to center, I am happy with this solution.
For anyone who is interested, here is my updated ColorCell constructor:
      public ColorCell() {
         setGraphic(rect);
         setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
//       How do I get the icon in the center of the table cell?
//       Adjust icon's translateX in accordance with the cell's width.
         widthProperty().addListener(new ChangeListener<Number>() {
            @Override public void changed(ObservableValue<? extends Number> ov,
                                Number oldWidth,
                                Number newWidth) {
               if (rect.isVisible()) {
                  rect.setTranslateX((newWidth.doubleValue() / 2)
                                              - (rect.getWidth() / 2));
      }

Similar Messages

  • I've problem with Game Center . I can't sign in Game Center on my iPad . I tap on the Game Center icon but the page is blank. I tried go to setting, my Apple ID appear but the page keep on loading and  nothing pop up. How to resolve this issue?

    I've problem with Game Center . I can't sign in Game Center on my iPad . I tap on the Game Center icon but the page is blank. I tried go to setting, my Apple ID appear but the page keep on loading and  nothing pop up. How to resolve this issue?

    Hi, bamboo64. 
    Try closing all open applications in multitasking and power cycling the device.  Once this is done test the results.  If the issue persists, I have included a couple troubleshooting articles that I would recommend going through. 
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Troubleshoot issues on an iPhone, iPad, or iPod touch
    If you haven't been able to connect to the iTunes Store:
    Make sure your date, time, and time zone are correct in Settings > General > Date & Time.
    Note: Time Zone may list another city in your time zone.
    Make sure that your iOS software is up to date by tapping Settings > General > Software Update (iOS 5 or later) or connecting your iOS device to iTunes and clicking Check for Update on your device's Summary page.
    Check and verify that you're in range of a Wi-Fi router or base station. If you're on a device with cellular service, make sure that cellular data is turned on from Settings > General > Cellular.
    Note: If connected to cellular data, larger items may not download. You may need to connect to Wi-Fi to download apps, videos, and podcasts.
    Make sure that you have an active Internet connection. You can check the user guide for your device for help with connecting to the Internet.
    Make sure that other devices (portable computers, for example) are able to connect to the Wi-Fi network and access the Internet.
    Try resetting (turning off and then on again) your Wi-Fi router.
    If the issue persists, try troubleshooting your Wi-Fi networks and connections.
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    Cheers,
    Jason H. 

  • How to change icon of a node or root node of a JTree

    i have a JTree with a root node, and leaf nodes. i want to change their icons. how can i do this?
    thanks

    Here's a search of the forums with the words 'tree', 'icon' and 'node' in the title
    http://onesearch.sun.com/search/developers/index.jsp?and=jtree+icon+node&nh=10&phr=&qt=&not=&field=title&since=&col=devforums&rf=0&Search.x=28&Search.y=15
    I looked at a couple and #5 seems interesting, but there are quite a few to choose from.

  • How to change the node's icon in a tree when the node collapse or expand?

    how to change the node's icon in a tree when the node collapse or expand?

    Hi,
    You may need to use custom skin for that.
    -Arun

  • MY CONTROL CENTER ICON DISAPPEARED HOW CAN I FIND IT?

    MY CONTROL CENTER ICON DISAPPEARED HOW CAN I GET IT BACK?

    bodhiapple,
    Go to your Applications Folder, and drag the Mission Control icon to your Dock.

  • How to not display nodes in a tree if Oracle roles are NOT used?

    How to not display nodes in a tree if Oracle roles are NOT used?
    We don't use Oracle DB roles to grant users access to Forms from the menu. We use a template and role system of our own. Basically a few tables with templates and roles.
    We want to convert our normal Forms menu to a tree menu and one of our key requirements is that when the tree is populated ONLY nodes with programs (i.e. forms) he has been granted to execute is shown.
    Since we don't use Oracle Roles how to do this in a tree?
    I created a function to show/hide LEAF nodes, BUT problem is that there are sub-menu nodes showing even if the leaf-nodes under it has not being displayed. My function has suppressed it.
    My tree query is like this:
    SELECT
         t.status, LEVEL, t.label, t.icon, t.node VALUE
    FROM
         tma_tree_menu t
    WHERE
    tma_authenticate_sys_chk_role(USER, t.node) = 1
    CONNECT BY
         PRIOR t.node = t.master
    START WITH
         t.MASTER IS NULL
    ORDER SIBLINGS BY
    t.position
    The tma_authenticate_sys_chk_role will return 1 only if the user has access to the form under that node.
    I tried the FTree functions in Forms but even that has nothing.
    Any help would be greatly appreciated.
    Edited by: Channa on Mar 17, 2010 6:49 AM

    Would you share the source code? I guess what I need is how exactly you retreive the user credentials from the DB table and set that boolean variable.
    and then how to condition it in UIX?

  • SAP BPC 5.1 "Client Software center" icons missing

    Hi,
    I had installed newly SAP BPC 5.1 (Single server installation) and installed Administration client & Office client on the server. It was successfully installed and all functionality was working fine.
    Now I want to access this server from client machine (desktops). The desktops has Microsoft Office 2007 installed and trying to access SAP BPC using http://<servername>/osoft
    I am able to get the home page, but when I click on icon "Client Software Center", I am not getting any icons for installing Client software (Ex: BPC for Office Installation, BPC client Diagnostics or BPC for Administration Installation)
    Appreciate if someone can help me on this.
    Cheers,
    RAJU

    That address should get you to the default landing page where you can access the software center.  Since this is a single server environment you should obvioulsy be addressing the web server.  I assume when you installed the client components on the server you were logged in as the service account that you installed the software with.  If you are connecting from your desktop using authentication, then you would be connecting with the ID and password that you login to your PC with.
    Have you gone through the BPC Administration security console and added your network ID to the application?  If not, then the system will know you are not a vaild system user and you would not be able to install the software.
    If you feel you have done this, then run the connection wizard and choose the option to connect with an alternate user ID and use the service account and verify you can access the software center.  If you can with the service account but not with your ID then it is a application security issue with how your network account is setup in the system.
    The other thing to check, when you say you cannot get the software center icon, are you getting the landing page and just not seeing it or are you getting a page error accessing the page?  If you are getting a page error and you did not use the default port to connect with then you would need to pass the port number through when you are addressing the server (e.g. http://servername/osoft:8080)

  • Numbers on Game Center icon

    For some time the Game Center icon has had the number "2" on it.  Today, while at the Apple Store, I once again opened the app to see if there was anything there which would clear the numbers.  Still can't find anything, but when I quit the app, it had changed to the number "3"!
    I talked to several people at the Apple store and no one could figure it out.  Any ideas?
    BTW, I have a weather app (not the Apple weather app, but it is called "The Weather" by Clink Apps) which also has a number ("1) on it's icon which I can't figure out how to get rid of.

    No one has experienced this?

  • How to create a node with attributes at runtime in webdynpro for ABAP?

    Hi Experts,
             How to create a node with attributes at runtime in webdynpro for ABAP? What classes or interfaces I should use? Please provide some sample code.
    I have checked IF_WD_CONTEXT_NODE_INFO and there is ADD_NEW_CHILD_NODE method. But this is not creating any node. I this this creates only a "node info" object.
    I even check IF_WD_CONTEXT_NODE but i could not find any method that creates a node with attribute.
    Please help!
    Thanks
    Gopal

    Hi
       I am getting the following error while creating a dynamic context node with 2 attributes. Please help me resolve this problem.
    Note
    The following error text was processed in the system PET : Line types of an internal table and a work area not compatible.
    The error occurred on the application server FMSAP995_PET_02 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: IF_WD_CONTEXT_NODE~GET_STATIC_ATTRIBUTES_TABLE of program CL_WDR_CONTEXT_NODE_VAL=======CP
    Method: GET_REF_TO_TABLE of program CL_SALV_WD_DATA_TABLE=========CP
    Method: EXECUTE of program CL_SALV_WD_SERVICE_MANAGER====CP
    Method: APPLY_SERVICES of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: REFRESH of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE_DATA of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~UPDATE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_VIEW~MODIFY of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMPONENT~VIEW_MODIFY of program CL_SALV_WD_A_COMPONENT========CP
    My code is like the following:
    TYPES: BEGIN OF t_type,
                CARRID TYPE sflight-carrid,
                CONNID TYPE sflight-connid,
             END OF t_type.
      Data:  i_struc type table of t_type,
      dyn_node   type ref to if_wd_context_node,
      rootnode_info   type ref to if_wd_context_node_info,
      i_node_att type wdr_context_attr_info_map,
      wa_node_att type line of wdr_context_attr_info_map.
          wa_node_att-name = 'CARRID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CARRID'.
          insert wa_node_att into table i_node_att.
          wa_node_att-name = 'CONNID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CONNID'.
          insert wa_node_att into table i_node_att.
    clear i_struc. refresh i_struc.
      select carrid connid into corresponding fields of table i_struc from sflight where carrid = 'AA'.
    rootnode_info = wd_context->get_node_info( ).
    rootnode_info->add_new_child_node( name = 'DYNFLIGHT'
                                       attributes = i_node_att
                                       is_multiple = abap_true ).
    dyn_node = wd_context->get_child_node( 'DYNFLIGHT' ).
    dyn_node->bind_table( i_struc ).
    l_ref_interfacecontroller->set_data( dyn_node ).
    I am trying to create a new node. That is
    CONTEXT
    - DYNFLIGHT
    CARRID
    CONNID
    As you see above I am trying to create 'DYNFLIGHT' along with the 2 attributes which are inside this node. The structure of the node that is, no.of attributes may vary based on some condition. Thats why I am trying to create a node dynamically.
    Also I cannot define the structure in the ABAP dictionary because it changes based on condition
    Message was edited by: gopalkrishna baliga

  • In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    In oracle rac, If user query a select query and in processing data is fetched but in the duration of fetching the particular node is evicted then how failover to another node internally?

    The query is re-issued as a flashback query and the client process can continue to fetch from the cursor. This is described in the Net Services Administrators Guide, the section on Transparent Application Failover.

  • How to change JTree nodes background?

    hello there
    i have a jtree which i set its background to red
    but the nodes background is still white
    why?and how to set the nodes background to red too?
    and how to remove the tree border
    because i tried setting it to null and it doesn't work?
    here is my code:
    package view;
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.tree.*;
    class TreeComponent{
      public static void main(String[] args) {
        JFrame frame = new JFrame("Creating a JTree Component!");
        DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Color", true);
        DefaultMutableTreeNode black = new DefaultMutableTreeNode("Black");
        DefaultMutableTreeNode blue = new DefaultMutableTreeNode("Blue");
        DefaultMutableTreeNode nBlue = new DefaultMutableTreeNode("Navy Blue");
        DefaultMutableTreeNode dBlue = new DefaultMutableTreeNode("Dark Blue");
        DefaultMutableTreeNode green = new DefaultMutableTreeNode("Green");
        DefaultMutableTreeNode white = new DefaultMutableTreeNode("White");
        parent.add(black);
        parent.add(blue);
        blue.add(nBlue);
        blue.add(dBlue);
        parent.add(green );
        parent.add(white);
        JTree tree = new JTree(parent);
        tree.setBackground(Color.red);
        tree.setBorder(null);
        frame.add(tree);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        frame.setSize(200,200);
        frame.setVisible(true);
    }

    how to set the nodes background to red too?
    ((JComponent) tree.getCellRenderer()).setOpaque(true);[/code\
    how to remove the tree borderWhat border?
    db                                                                                                                                                                                                                                                                                                                                       

  • How to blink TreeView Nodes based on condition c#

    suppose i am populating my tree view with data from database and i want to blink those nodes which has a specific data. now guide me with code how can i efficiently blink multiple tree view nodes  based on condition in winform application.

    Hi Mou_kolkata,
    >> anyone can give me small working code for tree node blinking
    Thank Armin for the details about blinking TreeView Nodes.
    For a simple demo to blink TreeView nodes, you could refer the link below:
    # Treeview control - How to make a node blink?
    https://social.msdn.microsoft.com/Forums/en-US/64e7a4d7-3098-4370-990f-390cb3a640a1/treeview-control-how-to-make-a-node-blink
    If you have issues when you blink Treeview nodes, please feel free to post a new thread in this forum, then you would get more help.
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to Delete the node from cluster when the machine crashed?

    In an three nodes Rac of 11g r2,How to delete the node from cluster when the machine crashed?
    There is now way to repair the machine and have to add a new one.
    What is step to follow up?

    hi
    IF YOU WANT TO DELETE RAC1 NODE
    check $./olsnodes
    1) delete the instance using dbca from any active nodes
    crs_stat -t
    srvctl stop asm -n rac1
    2) delete listener
    3) delete oracle_home from oracle user
    $ORACLE_HOME/bin/runInstaller -updatenodelist ORACLE_HOME=<db_home> "CLUSTER_NODES={RAC1}
    4)delete asm home
    $ORACLE_HOME/bin/runInstaller -updatenodelist ORACLE_HOME=<asm_home> "CLUSTER_NODES={RAC1}
    5) update cluster node
    $ORACLE_HOME/bin/runInstaller -updatenodelist ORACLE_HOME=<db_home> "CLUSTER_NODES={active nodes like rac2,rac3}
    6) update ASm home
    $ORACLE_HOME/bin/runInstaller -updatenodelist ORACLE_HOME=<asm_home> "CLUSTER_NODES={active nodes like rac2,rac3}
    cd $ORA_CRS_HOME
    cd crs/opmn/conf
    check for
    $cat ons.config
    remoteport=6200
    cd crs_home/bin
    $./racgons remove_config rac1:6200
    $ go to crs home
    and $ORA_CRS_HOME/crs/install/rootdelete.sh
    $ORA_CRS_HOME/crs/install/rootdeletenode.sh
    check for ./olsnodes

  • How to create Event Node in smartform

    Hi Experts,
    could you please tell me how to create event node in smartform
    Thanks in Advance,
    Thanks&Regards
    Geetha

    HI,
    plz explain your problem in deeply.
    And as per me you first create page and righ click on it
    Then create window as per your requirement.
    if you want to put condition ot events true or false Righ click on your window
    then goto flow logic -> Altenative
    You can found 2 events in Condition.
    So you can assign this events.If you want to put condition or event on test then goto Text here in General Attributes in bottom side you can find even on page.
    Try it.

  • How to edit the node value of a tree in webdynpro java

    Hi ALL
    I have Tree UI element where i got displayed all the nodes by calling the BAPI
    Now my requirement is when i put the cursor at any node in the Tree struture then on click of insert button i need to insert the new node with the text  , the user has to be option to give new text for the new node dynamically  , so while adding the new node in a tree the tree has to choose the text for new node , like how to edit the node of a tree to add new text.
    If any one can send the sample code on the same then it would be great help to me.
    Similar requirement like in table UI Like however we are adding the new row in a table when we click on the insert button then cursor will go to that new row in a table where user can enter his details in the table.. now i am looking for the same requirement in a Tree UI element.
    is it possible the same requirement in tree UI element in webdynpro for Java??
    Thanks
    kallki reddy

    Hi kallki reddy
    In general I think this is not possible in the form you'd like. It seems the Tree control is read-only thing always. It cannot provide editing capabilities.
    Table is different thing. You can select within many different cell editors including Input Fields.
    I guess that you scenario could be implemented not with Tree control, but with Table with Master Column. The master column allows to bring up a hierarchy into a plain table. So it's just a tree inside a table.
    Here you can find further details: [TreeByNestingTableColumn API|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/92/12a74046033913e10000000a155106/content.htm]
    BR, Siarhei

Maybe you are looking for