具有圓角和透明度的邊框
具有圓角和透明度的邊框
這個問題解決了創建具有透明度的圓角邊框的問題,允許底層組件顯示出來。解決方案涉及修改 TextBubbleBorder 類別以繪製邊框剪輯區域之外的父級的背景顏色。// Paint the BG color of the parent, everywhere outside the clip // of the text bubble. Component parent = c.getParent(); if (parent!=null) { Color bg = parent.getBackground(); Rectangle rect = new Rectangle(0,0,width, height); Area borderRegion = new Area(rect); borderRegion.subtract(area); g2.setClip(borderRegion); g2.setColor(bg); g2.fillRect(0, 0, width, height); g2.setClip(null); }對TextBubbleBorder 類別所做的修改如下如下://在剪輯之外的所有地方繪製父級的背景顏色 // 文字氣泡。 元件父級 = c.getParent(); 如果(父!=空){ 顏色背景=parent.getBackground(); 矩形 矩形 = new 矩形(0,0,寬度,高度); 區域邊框區域=新區域(矩形); borderRegion.subtract(區域); g2.setClip(borderRegion); g2.setColor(bg); g2.fillRect(0, 0, 寬度, 高度); g2.setClip(null); }
此程式碼會擷取父元件及其背景顏色。然後,它創建一個代表邊界區域的區域,並從中減去氣泡和指針區域。這定義了邊框之外的區域。
設定了剪輯區域後,程式碼將使用父組件的背景色填充該區域,使圓角之外的邊框透明。透過將指針大小設為 0,邊框會轉換為標準圓角矩形。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3