⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tpopupmenu.java

📁 全面实现ilog地功能,没有使用第三方lib.
💻 JAVA
字号:
/* * This source code is part of TWaver 1.3.1 * * SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Copyright 2000-2005 SERVA Software, Inc. All rights reserved. */package demo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;

import javax.swing.JPopupMenu;

import twaver.TWaverUtil;

public class TPopupMenu extends JPopupMenu{
	private String text = null;
	private Color topColor = null;
	private Color bottomColor = null;
	private Color foreColor = null;
	private Font font = TWaverUtil.getDefaultFont(); 
	private int width;
	
	public TPopupMenu(String text, Color foreColor, Color backgroundColor, int width){
		super();
		this.text = text;
		this.foreColor = foreColor;
		this.topColor = backgroundColor;
		this.bottomColor = backgroundColor;
		this.width = width;
	}
	public TPopupMenu(String text, Color foreColor, Color topColor, Color bottomColor, int width){
		super();
		this.text = text;
		this.foreColor = foreColor;
		this.topColor = topColor;
		this.bottomColor = bottomColor;
		this.width = width;
	}

    public Insets getInsets() {
        Insets insets = (Insets)super.getInsets().clone();
        insets.left += width;
        return insets;
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        // draw backgound
        Dimension size = this.getSize();
        Graphics2D g2 = (Graphics2D) g;
        GradientPaint gp = new GradientPaint(0, 0, topColor, 0, size.height, bottomColor, false);
        g2.setPaint(gp);
        g2.fillRect(0, 0, width, size.height);
        
        // draw text
        if(this.text != null && this.font != null){
            g2.setColor(this.foreColor);
            g2.setFont(font);
        	Dimension textSize = TWaverUtil.getTextSize(text, font, g2);
        	int y = (size.height + textSize.width)/ 2;
        	int xOffset = TWaverUtil.getTextOffset(text, font, g2);
        	TWaverUtil.drawString(text, g2, (width - textSize.height)/2 + xOffset, y, -Math.PI * 0.5);
        }
    }
	public Font getFont() {
		return font;
	}
	public void setFont(Font textFont) {
		this.font = textFont;
	}
    



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -