Search code examples
javaswingdrawingpaneljcolorchooser

Cannot get colorchooser to change line color


Been trying for over 6 hours now and I keep finding the same answers from everyone regarding the changing of a background color within a JPanel drawing frame. The problem is I don't want/need to touch the background color, its the line color on this mouse draw application I can't seem to get working at all.

Here is what I have so far, it's not done. I'm suppose to be putting a combo box in for line thickness selection and an erase function, but I can't get past this. HELP!

    JButton jButton_SetColour.setBounds(721, 104, 89, 23);
    frame_SetColour = new JButton("Colour");
    jButton.getContentPane().add(jButton_SetColour);
    jButton_SetColour.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent event){
          Color color = JColorChooser.showDialog(null,"Pick Your Colour", frame.getForeground());   
                if (color != null)frame.getContentPane();
                JColorChooser.setColor());
                }

                }

Solution

  • like i said, really new at this so it was perserverance and attention, but i managed to get it running.

        JButton jButton_sete = new JButton("Set Choice");
        jButton_sete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        drawColor = JColorChooser.showDialog(null, "Set Choice",choice);
            if (choice != null) {
                g2dImg.setPaint(choice);
        });
    

    i needed to understand how to associate the actionlistener to the choice variable through jColorChooser, rookie error.