3

Вопрос по swing, java – Как создать расширение JButton с закругленными углами?

Error: User Rate Limit ExceededError: User Rate Limit Exceeded [https://stackoverflow.com/questions/778222/make-a-button-round]Error: User Rate Limit Exceeded Error: User Rate Limit ExceededError: User Rate Limit ...

Error: User Rate Limit Exceeded

от John Gardner

4 ответа

1

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceeded

@Override
    protected void paintComponent(Graphics g)
    {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        Shape firstClip = g.getClip();
        RoundRectangle2D rect = new RoundRectangle2D.Double();
        double arc = Math.ceil(getSize().getHeight()/3);
        rect.setRoundRect(0, 0, Math.ceil(getSize().getWidth()), Math.ceil(getSize().getHeight()), arc, arc);
        Area secondClip = new Area(getBounds());
        secondClip.subtract(new Area(rect));
        Area finalClip = new Area(firstClip);
        finalClip.subtract(secondClip);
        g2.setClip(finalClip);
        super.paintComponent(g2);
        Color[] gradients;
        if(getModel().isRollover())
        {
            gradients = new Color[] { new Color(184, 207, 229), new Color(122, 138, 153), new Color(184, 207, 229) };
        }
        else
        {
            gradients = new Color[] { new Color(122, 138, 153) };
        }
        for(int i = 0; i < gradients.length; i++)
        {
            arc -= 2;
            g2.setColor(gradients[i]);
            g2.drawRoundRect(i+1, i+1, (int)Math.ceil(getSize().getWidth()-2)-(i*2), (int)Math.ceil(getSize().getHeight()-2)-(i*2), (int)arc, (int)arc);
        }
    }

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

  • first of all you can catch every kind of action that is used on the button to change the state (like in the code, where mouseIn is used to change a color)
  • then you have to care about every single paint detail you need, for example for gradients you should point to class GradientPaint that is used to draw gradients..

Error: User Rate Limit Exceeded

Похожие вопросы