關(guān)鍵知識點(diǎn)
1:
圓角效果
????(1)通過setClip設(shè)置剪切區(qū)域,只繪制圓角區(qū)域
????????????RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth(), this.getHeight(), 20, 20);
????????????g.setClip(rect);
????????????注意要在super之前設(shè)置
????(2)重載paintBorder方法繪制圓角邊框
????????????RoundRectangle2D.Double rect = new RoundRectangle2D.Double(1, 1, this.getWidth() - 2, this.getHeight() - 2, 20, 20);
??????????????g2d.setColor(new Color(0, 100, 100));
??????????????g2d.draw(rect);
2:
查詢圖標(biāo)
????(1)重載getInsets方法設(shè)置間隙
????(2)重載paintComponent繪制圖片和三角箭頭
3:
鼠標(biāo)及事件觸發(fā)
????(1)光標(biāo):添加addMouseMotionListener事件,在mouseMove中設(shè)置光標(biāo)
????????if (getIconBounds().contains(e.getPoint())) {
?????????????SearchTextField.this.setCursor(Cursor.getDefaultCursor());
????????} else {
?????????????SearchTextField.this.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
????????}
????(2)鼠標(biāo)點(diǎn)擊search圖標(biāo)事件:添加addMouseListener事件,在mouseClick中彈出菜單或做其它處理
????????if (getIconBounds().contains(e.getPoint())) {
????????????????JPopupMenu menu = new ZHTPopupMenu("menu");
????????????????for (int i = 1; i < 6; i++) {
????????????????JCheckBoxMenuItem item = new JCheckBoxMenuItem("item" + i);
????????????????menu.add(item);
????????????}
????????????menu.show(SearchTextField.this, getWidth() - 5, getHeight() - 2);
????????}
by
?????????zhangtao
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
