HOME
      • 분류 전체보기 (65)
        • Life (6)
          • 사진 (6)
        • Study (21)
          • 일상·회고 (2)
          • Tools (4)
          • Computer Science (4)
          • Computer Security (1)
          • Java (6)
          • Python3 (2)
          • Android (1)
          • CodeSignal (0)
          • 임시 (1)
        • Backend (16)
          • Data Structure (0)
          • Database (2)
          • WAS with JavaEE (10)
          • WAS with Spring Boot (0)
          • Ubuntu for Raspberry Pi (4)
          • Apache Spark 2.0 (0)
        • Frontend (22)
          • HTML5 (0)
          • CSS3 (0)
          • JavaScript (11)
          • TypeScript (0)
          • React·React Native (11)
      • 트위터
      • 인스타그램
      Today
      Yesterday
      Total
        • [Java] 자바 스윙 JTextField 꾸미기
          Study/Java 2020. 12. 8. 16:25
          반응형

             public class RoundJTextField extends JTextField {
                 private Shape shape;
                 public RoundJTextField(int size) {
                     super(size);
                     setOpaque(false); // As suggested by @AVD in comment.
                 }
                 protected void paintComponent(Graphics g) {
                      g.setColor(getBackground());
                      g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
                      super.paintComponent(g);
                 }
                 protected void paintBorder(Graphics g) {
                      g.setColor(getForeground());
                      g.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
                 }
                 public boolean contains(int x, int y) {
                      if (shape == null || !shape.getBounds().equals(getBounds())) {
                          shape = new RoundRectangle2D.Float(0, 0, getWidth()-1, getHeight()-1, 15, 15);
                      }
                      return shape.contains(x, y);
                 }
             }

          JTextField가 딱딱하지 않게 테두리를 둥글게 해서 고칠 수 있습니다.

          저 클래스를 넣으신 후, JTextField가 사용될 곳에 RoundJTextField를 넣으시면 JTextField와 동일하게 작동합니다.

          해당 클래스는 JTextField를 상속받은 클래스이기 때문에 기능은 그대로 동작하면서 외관만 바꾸는 효과를 나타낼 수 있습니다.

          반응형
          저작자표시 비영리 변경금지 (새창열림)

          'Study > Java' 카테고리의 다른 글

          [정보보호개론] Java로 RSA 암호문 해독하기 (RSA 복호화)  (0) 2021.04.07
          [정보보호개론] Java로 AES 복호화 프로그램 만들기  (0) 2021.04.02
          [Java] 클래스 메소드 vs 인스턴스 메소드 (자바 static 관련)  (0) 2021.02.23
          [Java] main메소드에서 "Cannot make a static reference to the non-static method run() from the type main" 오류 해결법  (0) 2020.12.08
          [Java] 자바 스윙 JButton 꾸미기 (둥근 버튼)  (10) 2020.11.21

          관련글 관련글 더보기

          • [정보보호개론] Java로 AES 복호화 프로그램 만들기
          • [Java] 클래스 메소드 vs 인스턴스 메소드 (자바 static 관련)
          • [Java] main메소드에서 "Cannot make a static reference to the non-static method run() from the type main" 오류 해결법
          • [Java] 자바 스윙 JButton 꾸미기 (둥근 버튼)

          댓글

        반응형

        인기포스트

        ABOUT ME

        LINK

        ADMIN

        admin 글쓰기
        Designed by Gabriel Ju Hyun Yoon, 2021

        티스토리툴바