⑴ java怎么样设置窗口透明而控件不透明
要完全点不到窗口只能点到组件可以设置窗口的形状。
⑵ java中窗体的标题栏如何设为透明
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import com.birosoft.liquid.LiquidLookAndFeel;
public class TestEvent extends JComponent
implements ComponentListener,WindowFocusListener {
private JFrame frame;
private boolean start = false;
private Image background;
private Point p;
// 获得当前屏幕快照
public void updateBackground() {
try {
Robot rbt = new Robot();
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
background = rbt.createScreenCapture(new Rectangle(0, 0, (int) dim
.getWidth(), (int) dim.getHeight()));
} catch (Exception ex) {
// p(ex.toString());
// 此方法没有申明过 ,因为无法得知上下文 。因为不影响执行效果 ,先注释掉它 ex.printStackTrace();
}
}
// 将窗口掉离出屏幕以获得纯粹的背景图象
public void refresh() {
if (start == true) {
this.updateBackground();
frame.setLocation(p);
if (p.x < 0 || p.y < 0)
frame.setLocation(0, 0);
this.repaint();
}
}
public void componentHidden(ComponentEvent e) {
System.out.println("Hidden");
}
// 窗口移动时
public void componentMoved(ComponentEvent e) {
System.out.println("moved");
this.repaint();
}
// 窗口改变大小时
public void componentResized(ComponentEvent e) {
System.out.println("resized");
this.repaint();
}
public void componentShown(ComponentEvent e) {
System.out.println("shown");
}
// 窗口得到焦点后,用refresh()方法更新界面
public void windowGainedFocus(WindowEvent e) {
System.out.println("gainedFocus");
refresh();
start = false;
}
// 窗口失去焦点后,将其移出屏幕
public void windowLostFocus(WindowEvent e) {
System.out.println("lostFocus");
if (frame.isShowing() == true) {
System.out.println("visible");
} else {
System.out.println("invisible");
}
start = true;
p = frame.getLocation();
frame.setLocation(-2000, -2000);
}
public TestEvent(JFrame frame) {
super();
this.frame = frame;
updateBackground();
this.setSize(200, 120);
this.setVisible(true);
frame.addComponentListener(this);
frame.addWindowFocusListener(this);
}
// 绘制外观,注意,其中 pos,offset 是为了将特定部分的图象贴到窗口上
public void paintComponent(Graphics g) {
Point pos = this.getLocationOnScreen();
Point offset = new Point(-pos.x, -pos.y);
g.drawImage(background, offset.x, offset.y, null);
}
/**
* @param args
*/
public static void main(String[] args) {
try {
// UIManager.setLookAndFeel("org.fife.plaf.Office2003.Office2003LookAndFeel");
// UIManager.setLookAndFeel("org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");
// UIManager.setLookAndFeel("org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");
UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
LiquidLookAndFeel.setLiquidDecorations(true);
// LiquidLookAndFeel.setLiquidDecorations(true, "mac");
// UIManager.setLookAndFeel(new SubstanceLookAndFeel());
// UIManager.setLookAndFeel(new SmoothLookAndFeel());
// UIManager.setLookAndFeel(new QuaquaLookAndFeel());
// UIManager.put("swing.boldMetal", false);
if (System.getProperty("substancelaf.useDecorations") == null) {
JFrame.(true);
// JDialog.(true);
}
System.setProperty("sun.awt.noerasebackground", "true");
// SubstanceLookAndFeel.setCurrentTheme(new
// SubstanceLightAquaTheme());
// UIManager.setLookAndFeel("org.fife.plaf.VisualStudio2005.VisualStudio2005LookAndFeel");
} catch (Exception e) {
System.err.println("Oops! Something went wrong!");
}
JFrame frame = new JFrame("Transparent Window");
TestEvent t = new TestEvent(frame);
t.setLayout(new BorderLayout());
JButton button = new JButton("This is a button");
t.add("North", button);
JLabel label = new JLabel("This is a label");
t.add("South", label);
frame.getContentPane().add("Center", t);
frame.pack();
frame.setSize(150, 100);
frame.show();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// t.start=true;
}
}
⑶ java JFrame制作透明窗口的问题
不明白你要的窗口透明到底是什么意思。不知道可不可以尝试添加不同的JPanel,一个专门用来做你所说的透明效果以及paint里面的操作,然后另一层JPanel来负责放置你得组件。建议多换思路多尝试。
⑷ java实现窗口全屏透明化,并在屏幕中显示汉字
// 将一个Frame最大化
if (f.isUndecorated()) {// 无边框窗口
f.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
}else{
f.setExtendedState(f.getExtendedState() | JFrame.MAXIMIZED_BOTH);
}
⑸ java怎么给窗体边框四周添加阴影和半透明
java swing是提供了设置阴影和透明度的方法的,示例如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.awt.AWTUtilities;
导入 AWTUtilities可能会提示:访问限制:由于对必需的库 C:\Program Files\Java\jre6\lib\rt.jar 具有一定限制,因此无法访问类型 AWTUtilities,请到eclipse进行设置:窗口》首选项》java》编译器》错误警告 选择 代码样式》访问外层不可访问成员》 把错误修改成功 警告
public class Ceshi extends JFrame
{
public Ceshi()
{
JLabel label=new JLabel("这是一个标签!");
label.setOpaque(false);
label.setHorizontalAlignment(JLabel.CENTER);
add(label);
setSize(600,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//Opacity最大值为1.0f,也就是什么也不透明,取值不能大于1.0f
AWTUtilities.setWindowOpacity(this,0.5f);
setVisible(true);
}
public static void main(String[] args)
{
new Ceshi();
}
}
⑹ java透明窗口问题求教
这纯粹是Timer类使用错误:
第一个错误说明你的source的问题,Timer是没有stop方法的,停止Timer是用cancel()方法;
第二个错误时你new Timer的时候参数不对,Timer的构造方法有Timer(),Timer(boolean isDaemon),Timer(String name),Timer(String name,boolean isDaemon),Timer类也没有start方法。
你这计时器的用法有问题。
⑺ 在java中怎么设置滚动面板为透明
设置颜色:
把pan - pan6的Background设为Null,这样他们就变为透明的了,以后只需要改变inquestFrame的颜色就可以改变全部的颜色,代码如下:
// 设置整体布局
JPanel pan = new JPanel();
pan.setLayout(new GridLayout(6, 1));
pan.add(pan1);
pan.add(pan2);
pan.add(pan3);
pan.add(pan4);
pan.add(pan5);
pan.add(pan6);
pan.setBackground(null);
pan1.setBackground(null);
pan2.setBackground(null);
pan3.setBackground(null);
pan4.setBackground(null);
pan5.setBackground(null);
pan6.setBackground(null);
r1.setBackground(null);
r2.setBackground(null);
inquestFrame.setBackground(Color.LIGHT_GRAY);
inquestFrame.setContentPane(pan);
inquestFrame.setSize(300, 250);
inquestFrame.setVisible(true);
设置图片需要改的比较多,自己比较那不一样吧:
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Inquest {
JFrame inquestFrame;
JLabel lab1, lab2, lab3, lab4, lab5, lab6;
JTextField text1, text2, text4, text5, text6;
JRadioButton r1, r2;
JButton inqButton;
public Inquest() {
inquestFrame = new JFrame("教育经历管理系统-查询窗口");
MyPanel pan1 = new MyPanel();
lab1 = new JLabel("请输入编码:");
text1 = new JTextField(10);
inqButton = new JButton(" 查询");
inqButton.addActionListener(new ButtonHandler());
pan1.add(lab1);
pan1.add(text1);
pan1.add(inqButton);
MyPanel pan2 = new MyPanel();
lab2 = new JLabel("姓名:");
text2 = new JTextField(10);
pan2.add(lab2);
pan2.add(text2);
MyPanel pan3 = new MyPanel();
lab3 = new JLabel("性别:");
r1 = new JRadioButton("男");
r2 = new JRadioButton("女");
// 把两个单选按钮放到一个群组中,保持二选一
ButtonGroup group = new ButtonGroup();
group.add(r1);
group.add(r2);
pan3.add(lab3);
pan3.add(r1);
pan3.add(r2);
MyPanel pan4 = new MyPanel();
lab4 = new JLabel("单位:");
text4 = new JTextField(10);
pan4.add(lab4);
pan4.add(text4);
MyPanel pan5 = new MyPanel();
lab5 = new JLabel("职位:");
text5 = new JTextField(10);
pan5.add(lab5);
pan5.add(text5);
MyPanel pan6 = new MyPanel();
lab6 = new JLabel("年龄:");
text6 = new JTextField(10);
pan6.add(lab6);
pan6.add(text6);
// 设置整体布局
MyPanel pan = new MyPanel();
pan.setLayout(new GridLayout(6, 1));
pan.add(pan1);
pan.add(pan2);
pan.add(pan3);
pan.add(pan4);
pan.add(pan5);
pan.add(pan6);
pan.setBackground(null);
pan1.setBackground(null);
pan2.setBackground(null);
pan3.setBackground(null);
pan4.setBackground(null);
pan5.setBackground(null);
pan6.setBackground(null);
r1.setBackground(null);
r2.setBackground(null);
MyPanel pan0 = new MyPanel();
pan0.setPreferredSize(pan.getPreferredSize());
pan0.setLayout(null);
pan.setBounds(0, 0, pan.getPreferredSize().width, pan.getPreferredSize().height);
URL url = Inquest.class.getResource("Winter.jpg");
ImageIcon img = new ImageIcon(url);
JLabel lab = new JLabel(img);
lab.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
pan0.add(pan);
pan0.add(lab);
inquestFrame.setContentPane(pan0);
inquestFrame.pack();
inquestFrame.setVisible(true);
}
public static class MyPanel extends JPanel {
public void paint(Graphics g) {
paintChildren(g);
}
}
public void setBack() {
((JPanel) inquestFrame.getContentPane()).setOpaque(false);
// Winter.jpg这个图片的位置要跟当前这个类是同一个包下
URL url = Inquest.class.getResource("Winter.jpg");
ImageIcon img = new ImageIcon(url);
JLabel background = new JLabel(img);
inquestFrame.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
// 生成SQL语句
String s = "select * from information where id=" + "'" + text1.getText() + "'";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:test";
// DB db = new DB(driver, url, "sa", "");
// ResultSet rs = db.query(s);
// try {
// while (rs.next()) {
// text2.setText(rs.getString(2));
// String sex = rs.getString(3);
// if (sex.trim().equals("男"))
// r1.setSelected(true);
// else
// r2.setSelected(true);
//
// text4.setText(rs.getString(4));
// text5.setText(rs.getString(5));
// text6.setText(rs.getString(6));
// }
// } catch (Exception e2) {
// e2.printStackTrace();
// }
}
}
public static void main(String args[]) {
new Inquest();
}
}
⑻ java窗口透明化
这个问题应该是你没有导入com.sun.awt.awt.awt.AWTUtilities这个包,因为以com或者sun开头的包不是javase基础类库中的包,所以你要是在使用它们的时候需要单独设置它们,如果你使用的是myeclipse的话,你可以这样进行配置
右键项目名称----->Propreties------>Libraries------>展开JRE(单击JRE System...前面的+号)------>双击Access Rule...------>单击add------>把Forbidden变为Accessible 同时Rule Pattern中添加 com/**----->确定完毕了~~~~
⑼ java 窗口内背景透明是用哪个列做的
panel之类的内部窗体的话setOpaque(false) 设置一下这个就会透明了...不过要是jframe之类的窗体..那就得自己去截取背景图来作为窗体的背景了
⑽ java JFrame窗口透明组件不透明该怎么实现
JPanel.setOpaque(false); //false透明,true不透明