swing JTable学习(四)—setTooltips换行

package ToolTipTest;


import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

//import Com.HtmlMultiLineControl;

public class CopyOfToolTipDemo extends JFrame {

    private JLabel lblTest;
    private JTextField textTest;
    private JButton btnTest;
  
    private String tipsArray="第一行,第二行,第三行";
    
    
    /**构造方法*/
    public CopyOfToolTipDemo(){
        
        CreateContence();
    }
    
    /*创建控件*/
    public void CreateContence(){
        
        String strDestTips = new String();
        
        setSize(450, 300);
        this.setLocation(this.getToolkit().getScreenSize().width / 2- this.getWidth() / 2,
                         this.getToolkit().getScreenSize().height/ 2 - this.getHeight() / 2);
        
        this.setLayout(null);
        
        lblTest = new JLabel("This is a ToolTipsText Wrap Test Label");
        lblTest.setBounds(new Rectangle(100,50, 260,30));
        lblTest.setToolTipText(getTips());//最终要显示提示信息
        getContentPane().add(lblTest);
        
    
        textTest = new JTextField("This is a ToolTipsText Wrap Test Text");
        textTest.setBounds(new Rectangle(100,100, 260,30));
        textTest.setToolTipText(getTips());
        getContentPane().add(textTest);
        
        btnTest = new JButton("This is a ToolTipsText Wrap Test Button");
        btnTest.setBounds(new Rectangle(100,150, 260,30));
        btnTest.setToolTipText(getTips());
        getContentPane().add(btnTest);
        
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    /*获取提示信息*/
    public String getTips(){
        
        HtmlMultiLineControl hmlc = new HtmlMultiLineControl();
        String strtemp = new String();
        
        if(tipsArray == null || "".equals(tipsArray)){
        	return tipsArray;
        }
        
        String []temp = tipsArray.split(",");
       
        
        for(int i=0; i<temp.length; i++){
            
            if(i!= 0){
                strtemp = strtemp + "<br>" ;//br:换行(HTML)
            }
            
            strtemp = strtemp + temp[i];
            System.out.println(temp.length);
        }
        
        //添加HTML格式控制
        strtemp = hmlc.CovertDestionString(strtemp);
        
        return strtemp;
    }
    public static void main(String[] args) {
        CopyOfToolTipDemo tooltip = new CopyOfToolTipDemo();
    }

}



package ToolTipTest;

public class HtmlMultiLineControl {
    
    private String strDest;
    //上文
    private final String strHtmlBegin = 
           "<html>"
        //      + "<bgcolor color=#000080>"
          //        +"<font color=#0000cd >"
                  +"<b>";
    //下文
    private final String strHtmlEnd = 
                  "</b>"
            //     +"</font>"
            // +"</bgcolor>"
          +"</html>";
    
    
    
    public String CovertDestionString(String strDest){
        
        this.strDest = strHtmlBegin + strDest + strHtmlEnd;
        //this.strDest = strDest;
    	return this.strDest;
    } }
  //END 


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值