Search code examples
javaswingjradiobutton

Switch Like Interface using JRadioButtons


Can anyone please tell me how to make an interface like that which is been shown below. Right now i'm using two JRadioButton for implementing that task. My code which i've done is shown below

JRadioButton but1 = new JRadioButton("Option 1");
JRadioButton but2 = new JRadioButton("Option 2");

ButtonGroup db=new ButtonGroup();
db.add(but1);
db.add(but2);

But how can we make the interface shown in the picture which does the same task that i've done through JRadioButtons.

enter image description here


Solution

    • required custom Icons and two JToggleButtons chained by ItemListener

    • create JSlider with two ranges (required custom painting)

    • great idea by @oliholz