Search code examples
javacheckboxradio-buttonworldwind

JAVA WorldWind LayerTree with Radio Buttons


WorldWind LayerTree uses checkboxes for default configuration. Is there any way to change checkboxes to radio-buttons?

Screenshot


Solution

  • I could not find any solution for replacing check boxes with radio-buttons. So, I decided to try another approach and it works for me. I catch the property change event of LayerTree and reset the selected nodes other than the newly selected one.

    LayerTree layerTree = new LayerTree();
    layerTree.addPropertyChangeListener(new PropertyChangeListener(){
        @Override
        public void propertyChange(PropertyChangeEvent evt) {   
            for (Iterator<TreeNode> treeNode = layerTree.getModel().getRoot().getChildren().iterator(); treeNode.hasNext(); ) {
                   LayerTreeNode layerTreeNode = LayerTreeNode.class.cast(treeNode.next());
                   if(evt.getSource() instanceof LayerTreeNode && evt.getSource() != layerTreeNode)
                    layerTreeNode.setSelected(false);
            }       
        }       
    });