Colors
The color picker is from JColorChooser and has several default tabs. During a for loop, only the "RGB" tab is displayed and the extra tabs like "Swatches" are hidden. Since the repaint() is called after every time the mouse clicks, drags, or lifts, then the transparent lines are compounded on top of each other. The alpha values, which normally affect transparency, will only affect the fade-in animation and not the transparency of the overall line. I converted the RGBA values to RGB so that the color of the menu button matches the current color of the paint tool.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | private void selectColor() { // When the user selects on the color button JColorChooser chooser = new JColorChooser(); // Color panel AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); for (AbstractColorChooserPanel accp : panels) { // Only the RGB tab will show if (accp.getDisplayName().equals( "RGB" )) { JOptionPane.showMessageDialog( null , accp); } } paintLab.repaint(); // Repaints the window in case some of the graphics disappeared due to the color chooser popping up Color pColor = chooser.getColor(); // Since transparent lines are compounded on top of each other when draw in succession causing the transparent lines to appear opaque // I converted the RGBA values into RGB. // Now, the color of the menu's color button matches the color drawn on the canvas int r, g, b; r = pColor.getRed() * pColor.getAlpha() + pColor.getRed() * ( 255 - pColor.getAlpha()); g = pColor.getGreen() * pColor.getAlpha() + pColor.getGreen() * ( 255 - pColor.getAlpha()); b = pColor.getBlue() * pColor.getAlpha() + pColor.getBlue() * ( 255 - pColor.getAlpha()); paintColor = new Color(r / 255 , g / 255 , b / 255 ); changeColorMenu(); } |
private void selectColor() { // When the user selects on the color button JColorChooser chooser = new JColorChooser(); // Color panel AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); for (AbstractColorChooserPanel accp : panels) { // Only the RGB tab will show if (accp.getDisplayName().equals("RGB")) { JOptionPane.showMessageDialog(null, accp); } } paintLab.repaint(); // Repaints the window in case some of the graphics disappeared due to the color chooser popping up Color pColor = chooser.getColor(); // Since transparent lines are compounded on top of each other when draw in succession causing the transparent lines to appear opaque // I converted the RGBA values into RGB. // Now, the color of the menu's color button matches the color drawn on the canvas int r, g, b; r = pColor.getRed() * pColor.getAlpha() + pColor.getRed() * (255 - pColor.getAlpha()); g = pColor.getGreen() * pColor.getAlpha() + pColor.getGreen() * (255 - pColor.getAlpha()); b = pColor.getBlue() * pColor.getAlpha() + pColor.getBlue() * (255 - pColor.getAlpha()); paintColor = new Color(r / 255, g / 255, b / 255); changeColorMenu(); }