2013-03-12 3 views
1

나는 마스터 마인드 게임을 만들고 JButtons로 매트릭스를 채워 사람들이 색상을 바꾸기 위해 클릭 할 수있게했습니다.JButton의 모양 변경

이제 직사각형 버튼의 모양을 원으로 변경하고 싶습니다. 루프를 사용하여 모든 항목을 만들었 기 때문에 한 번에 변경할 수 있습니다.

답변

2

Google에 대한 자습서를 검색 할 수 있습니다. 여기 How to change the shape of a JButton

+0

는 [링크 전용 답변 삭제 경향] 조심 (http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links- 다른 곳에서 - 정말 좋은 답변들) –

5

구성 요소의 모양을 편집 덮어 쓸 수있는 몇 가지 방법됩니다

이 쉬운 튜토리얼입니다. (샘플 코드 포함)

protected void paintComponent(Graphics g) 
    { 
    if (getModel().isArmed()) { 
     g.setColor(Color.lightGray); 
    } else { 
     g.setColor(getBackground()); 
    } 
    g.fillOval(0, 0, getSize().width-1,getSize().height-1); 

    super.paintComponent(g); 
    } 

    protected void paintBorder(Graphics g) { 
    g.setColor(getForeground()); 
    g.drawOval(0, 0, getSize().width-1,  getSize().height-1); 
    } 

    Shape shape; 
    public boolean contains(int x, int y) { 
    if (shape == null || 
     !shape.getBounds().equals(getBounds())) { 
     shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight()); 
    } 
    return shape.contains(x, y); 
    }