[ Mr. Rejn @ 20.10.2007. 20:39 ] @
Kako da to uradim,imam klasu zaobljenog dugmeta izvedenu iz Swing JButton,
ali ne znam kako da mu dodam onu normalnu 3D ivicu koju ima običan JButton.

Code:

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class RoundButton extends JButton {
    public RoundButton(String label) {
        super(label);

        // These statements enlarge the button so that it
        // becomes a circle rather than an oval.
        Dimension size = getPreferredSize();
        size.width = size.height = Math.max(size.width, size.height);
        setPreferredSize(size);

        // This call causes the JButton not to paint the background.
        // This allows us to paint a round background.
        setContentAreaFilled(false);
    }

    // Paint the round background and label.
    protected void paintComponent(Graphics g) {
        if (getModel().isArmed()) {
            // You might want to make the highlight color
            // a property of the RoundButton class.
            g.setColor(Color.lightGray);
        } else {
            g.setColor(getBackground());
        }
        g.fillRoundRect(0, 0, getSize().width-1, getSize().height-1,15,15);

        // This call will paint the label and the focus rectangle.
        super.paintComponent(g);
    }

    // Paint the border of the button using a simple stroke.
    protected void paintBorder(Graphics g) {
        g.setColor(getForeground());
        g.drawRoundRect(0, 0, getSize().width-1, getSize().height-1,15,15);
    }

    // Hit detection.
    Shape shape;
    public boolean contains(int x, int y) {
        // If the button has changed size, make a new shape object.
        if (shape == null || !shape.getBounds().equals(getBounds())) {
           // shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
            shape = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(),15,15);
        }
        return shape.contains(x, y);
    }
    // konstruktor:
  RoundButton() {}
}

[ nemnesic @ 22.10.2007. 06:23 ] @
http://www.java2s.com/Code/Jav...borderbuttonborder3Dborder.htm
http://www.java2s.com/Code/Java/3D/Swingand3Dbook.htm
http://www.jroller.com/gfx/entry/a_jbutton_with_3d_follow
[ Mr. Rejn @ 22.10.2007. 19:35 ] @
^
Linkovi su pomogli,to je to..koji metod trebam sad da promenim/dodam u ovoj klasi da bi se pri
kliku (akciji dugmeta) pojavila ona udubljena ivica (ista ovakva samo inverzna-dobija se
kada se zamene mesta lightColor i darkColor u metodi paintBorder) koja daje onaj efekat "dubine"?
Znaci kako da dodam ono standardno ponasanje senke dugmeta pri kliku ovom zaobljenom dugmetu?
[ nemnesic @ 22.10.2007. 19:45 ] @
Mr. Rejn,

a jel mogu da pitam sta ce ti sve ovo...ovaj eye candy?

nn
[ Mr. Rejn @ 22.10.2007. 20:54 ] @
Možeš,pitaj...
Hoću da mi GUI izgleda lepo kako bih ga lakše uvalio korisnicima (bolji izgled mu
malo kompenzuje sporost).Komponente izgledaju privlačnije sa tim zaobljenim izgledom.
[ nemnesic @ 22.10.2007. 21:15 ] @
pa zar ne mozes da nadjes neki lepi look an feel umesto da sve kucas?
[ Mr. Rejn @ 22.10.2007. 22:47 ] @
Pa dobro, računam da nije to toliko kucanje,potrebno mi je samo to rukovanje izgledom zaobljene
ivice pri kliku na dugme. Što se tiče LAF-ova, nisam mogao da ih poteram jer mi se javljaju greške
pri učitavanju klasa (substance i synthetica LAF-ovi),ali da ne idemo OT.Nije to razlog zašto
pravim zaobljene ivice na GUI-jednostavno su estetski lepše od pravougaonih.