Custom SmartDashboard Widget

I have been trying to get a basic custom widget working on the SmartDashboard for a couple weeks now, but I’ve gotten very lost in the changes they’ve made in the API since 2012. Right now, I am just trying to create a widget that reads and writes to its associated NetworkTable (it’s being created from a putData(Subsystem s) call). However, I am not able to read or write from the NetworkTable through any diplomatic means. I’ve tried extending Widget and AbstractTableWidget, with no luck on either. I don’t even get a setValue() method call or a valueChanged() call.

If anyone has created their own widget on SmartDashboard for 2013 code, please help!

I haven’t made a widget personally, but the people who made SmartDashboard have made quite a few! Here’s CheckBox from the SmartDashboard source code:

package edu.wpi.first.smartdashboard.gui.elements;

import edu.wpi.first.smartdashboard.gui.elements.bindings.AbstractValueWidget;
import javax.swing.*;

import edu.wpi.first.smartdashboard.properties.*;
import edu.wpi.first.smartdashboard.types.*;

/**
 * Implements a simple text box UI element with a name label.
 * @author pmalmsten
 */
public class CheckBox extends AbstractValueWidget {

    public static final DataType] TYPES = {DataType.BOOLEAN};

    public final BooleanProperty editable = new BooleanProperty(this, "Editable", true);
    
    private EditableBooleanValueCheckBox valueField;

    public void init() {
        setResizable(false);

        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

        valueField = new EditableBooleanValueCheckBox(getFieldName());

        add(valueField);
    }

    @Override
    public void propertyChanged(Property property) {
        if (property == editable) {
            valueField.setEnabled(editable.getValue());
        }
    }
}

AbstractTableWidget is fairly easy to get started with, because it binds NetworkTables variables to your objects of type StringTableField, NumberTableField, BooleanTableField or BooleanTableCheckBox. You don’t need to write any NetworkTables code. The sending data and receiving data happens automatically if there is a change.

I found it helpful to look at how the PIDEditor was implemented in SmartDashboard.

I made a few extensions that extended PIDEditor. You can see them here: http://forums.usfirst.org/showthread.php?t=20437