Function Repository Resource:

StyledCheckboxBar

Source Notebook

Create a style-customizable checkbox bar

Contributed by: Soumya Sambeet Mohapatra, Jayanta Phadikar and Kunal Khadke

ResourceFunction["StyledCheckboxBar"][x,{val1,val2 ,val3}]

represents a styled checkbox bar with setting x and with checkboxes for values vali to include in the List x.

ResourceFunction["StyledCheckboxBar"][Dynamic[x],{val1,val2 ,val3}]

takes the setting to be the dynamically updated current value of x, with the values in the List x being reset every time a checkbox is clicked.

Details and Options

ResourceFunction["StyledCheckboxBar"] is built using the top-level Dynamic and Graphics functionalities in the Wolfram Language.
In comparison to the built-in CheckboxBar, ResourceFunction["StyledCheckboxBar"] is much more flexible in terms of the styling (e.g. hover color) of the checkboxes.

Examples

Basic Examples (2) 

A StyledCheckboxBar with default states:

In[1]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x1], {1, 2, 3, 4, 5}]
Out[1]=

The second argument can be a List of rules of the form value label:

In[2]:=
{ResourceFunction["StyledCheckboxBar"][
  Dynamic[x2], {1 -> "One", 2 -> "Two", 3 -> "Three"}], Dynamic[x2]}
Out[2]=

Scope (1) 

Any Wolfram Language expression can be used as the label:

In[3]:=
a = Plot[Sin[x], {x, 0, 2 \[Pi]}, ImageSize -> 40, Axes -> False];
b = (-1 + Sqrt[5])/2;
c = ImageResize[ExampleData[{"TestImage", "Girl"}], 40];
In[4]:=
ResourceFunction["StyledCheckboxBar"][
 Dynamic[exp], {1 -> a, 2 -> b, 3 -> c}]
Out[4]=

Options (8) 

Appearance (5) 

Appearance can be used to change the colors of the different states. Use the sub-option "InactiveColor" to change color when the state is False:

In[5]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x3], Range[5], Appearance -> {"InactiveColor" -> LightRed}]
Out[5]=

The sub-option "ActiveColor" modifies the color when the state is True:

In[6]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x4], Range[5], Appearance -> {"InactiveColor" -> LightRed, "ActiveColor" -> Darker[Green]}]
Out[6]=

"Hover" modifies the color when the mouse is hovered over the checkbox when it is in the False state:

In[7]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x5], Range[5], Appearance -> {"InactiveColor" -> LightRed, "ActiveColor" -> Darker[Green], "Hover" -> LightBlue}]
Out[7]=

"CheckColor" modifies the color of the check mark when in the True state:

In[8]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x6], Range[5], Appearance -> {"InactiveColor" -> LightRed, "ActiveColor" -> Darker[Green], "Hover" -> LightBlue, "CheckColor" -> Black}]
Out[8]=

"Alignment" can be used to arrange the layout either horizontally or vertically:

In[9]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x7], Range[5], Appearance -> {"Alignment" -> "Vertical"}]
Out[9]=

Specify the number of rows or columns as second item in the list:

In[10]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x8], Range[5], Appearance -> {"Alignment" -> {"Vertical", 2}}]
Out[10]=

Enabling/Disabling (1) 

Setting Enabled to False prevents the checkbox bar from being controllable:

In[11]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x9], {1, 2, 3}, Enabled -> False]
Out[11]=

Spacings (1) 

Adjust the spacings between individual checkboxes:

In[12]:=
Column[Table[
  ResourceFunction["StyledCheckboxBar"][Dynamic[x10], {1, 2, 3}, Spacings -> space], {space, 3}]]
Out[12]=

Magnification (1) 

Increase the size of the checkboxes:

In[13]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[x11], Range[5], Magnification -> 1.5]
Out[13]=

Properties and Relations (2) 

StyledCheckboxBar and CheckboxBar are similar in functionality:

In[14]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[t1], Range[5]]
Out[14]=
In[15]:=
CheckboxBar[Dynamic[t2], Range[5]]
Out[15]=

However, various stylings e.g. "InactiveColor" cannot be specified in the checkboxes, in contrast to StyledCheckbox:

In[16]:=
ResourceFunction["StyledCheckboxBar"][Dynamic[t3], Range[5], Appearance -> {"InactiveColor" -> LightGreen}]
Out[16]=

Publisher

Jayanta Kumar Phadikar

Version History

  • 1.0.0 – 26 April 2021

Related Resources

License Information