简体   繁体   中英

JRadioButton in Graphic2D

I want to draw radiobuttons panel in Graphic2D but I don't know how can I do this.

@Override
    public void draw(Graphics2D g2)
    {
      // ... Here I draw some Recntangle2D objects....

    }

And here is simple jbuttonpanel with radio buttons:

 public ButtonGroup buttons() {
        JRadioButton button1 = new JRadioButton("Red");
        JRadioButton button2 = new JRadioButton("Green");
        JRadioButton button3 = new JRadioButton("Blue");
        ButtonGroup colorButtonGroup = new ButtonGroup();
        colorButtonGroup.add(button1);
        colorButtonGroup.add(button2);
        colorButtonGroup.add(button3);
        button1.setSelected(true);
        return colorButtonGroup;
    }

But I don't know how can I draw it in upper method on top where below my buttonpanel I draw some recntagles with text field.

You don't draw radio buttons. You add the radio buttons (like any other Swing component) to the panel and the panel will paint the buttons for you.

Read the section from the Swing tutorial on How to Use Radio Buttons for more information and working examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM