swt text设置文本宽_java Swt 中如何设置Text框和Button按钮透明

这个是用图片的

package sample;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Rectangle;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Frame extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JButton jButton = null;

private JPanel jPanel = null;

/**

* This is the default constructor

*/

public Frame() {

super();

initialize();

}

/**

* This method initializes this

*

* @return void

*/

private void initialize() {

this.setSize(513, 309);

this.setContentPane(getJContentPane());

this.setTitle("JFrame");

}

/**

* This method initializes jContentPane

*

* @return javax.swing.JPanel

*/

private JPanel getJContentPane() {

if (jContentPane == null) {

jContentPane = new JPanel();

jContentPane.setLayout(null);

jContentPane.add(getJPanel(), null);

}

return jContentPane;

}

/**

* This method initializes jButton

*

* @return javax.swing.JButton

*/

private JButton getJButton() {

if (jButton == null) {

jButton = new JButton();

jButton.setBounds(new Rectangle(34, 27, 150, 44));

jButton.setText("愛我老婆");

jButton.setBorder(null);

//下面这句设置背景颜色必须要否则无法实现背景透明

jButton.setBackground(Color.BLACK);

jButton.setOpaque(false);

jButton.setForeground(Color.red);

jButton.setFont(new Font("",Font.BOLD,24));

}

return jButton;

}

class getpane extends JPanel {

private static final long serialVersionUID = 1L;

int width = 0, hight = 0;

String imgpath = "";

public getpane(int width, int hight, String imgpath) {

this.width = width;

this.hight = hight;

this.imgpath = imgpath;

this.setOpaque(true);

}

protected void paintComponent(Graphics g) {

super.paintComponent(g);

ImageIcon icon = new ImageIcon(imgpath);

Image img = icon.getImage();

g.drawImage(img, 0, 0, width, hight, this);

}

}

/**

* This method initializes jPanel

*

* @return javax.swing.JPanel

*/

private JPanel getJPanel() {

if (jPanel == null) {

String imgpath = "src/game/image/good02.jpg";

jPanel = new getpane(this.getWidth(), this.getHeight(), imgpath);

// jPanel = new JPanel();

jPanel.setLayout(null);

jPanel.setBounds(new Rectangle(13, 8, 472, 251));

jPanel.add(getJButton(), null);

}

return jPanel;

}

}

2010年6月04日 12:13

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值