public class JFrameBackground extends JFrame {
public JFrameBackground() {
this.setTitle("我的swing界面");
JPanel panel = new JPanel();
panel.setBackground(null);
panel.setOpaque(false);
this.setSize(300, 300);
this.getContentPane().add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new JFrameBackground();
}
}
already set setOpaque how not transparent ?
------ Solution ---------------------------------------- ----
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameBackground extends JFrame {
public JFrameBackground() {
this.setTitle("我的swing界面");
JLabel someText = new JLabel("透明的哦");
GradientPanel gradientPanel = new GradientPanel();
gradientPanel.add(someText);
this.add(gradientPanel);
this.setSize(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new JFrameBackground();
}
}
class GradientPanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(new GradientPaint(0, 0, Color.RED, 0, h, Color.WHITE));
g2d.fillRect(0, 0, w, h);
}
}
------ For reference only ---------------------------- -----------
just set up a panel transparent .
------ For reference only -------------------------------------- -
Thank you for your replies , is there any possibility jpanel direct and transparent display the desktop background ?
------ For reference only -------------------------------------- -
to use jna 's .
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.sun.jna.platform.WindowUtils;
public class JFrameBackground extends JFrame {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(500, 500, 300, 300);
System.setProperty("sun.java2d.noddraw","true");
WindowUtils.setWindowAlpha(frame, 0.5f);
JPanel pane = new JPanel() {
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.fill3DRect(10, 10, 100, 100, true);
}
};
frame.setContentPane(pane);
frame.setVisible(true);
}
}
------ For reference only ----- ----------------------------------
how to run your code being given it ? :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.sun.jna.platform.WindowUtils$Holder.<clinit>(WindowUtils.java:570)
at com.sun.jna.platform.WindowUtils.getInstance(WindowUtils.java:589)
at com.sun.jna.platform.WindowUtils.setWindowAlpha(WindowUtils.java:1533)
at frametm.JFrameBackground.main(JFrameBackground.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
jar package also guide , my guide is jna-platform.jar.
------ For reference only -------------------------------------- -
how to run your code being given it ? :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.sun.jna.platform.WindowUtils$Holder.<clinit>(WindowUtils.java:570)
at com.sun.jna.platform.WindowUtils.getInstance(WindowUtils.java:589)
at com.sun.jna.platform.WindowUtils.setWindowAlpha(WindowUtils.java:1533)
at frametm.JFrameBackground.main(JFrameBackground.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
jar package also guide , my guide is jna-platform.jar.
under 3.3.0 version : http://download.csdn.net/detail/huxiweng/6545223
- ----- For reference only ---------------------------------------
quote = 6F huxiweng quote reply : ]
how to run your code being given it ? :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.sun.jna.platform.WindowUtils$Holder.<clinit>(WindowUtils.java:570)
at com.sun.jna.platform.WindowUtils.getInstance(WindowUtils.java:589)
at com.sun.jna.platform.WindowUtils.setWindowAlpha(WindowUtils.java:1533)
at frametm.JFrameBackground.main(JFrameBackground.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
jar package also guide , my guide is jna-platform.jar.
under 3.3.0 version : http://download.csdn.net/detail/huxiweng/6545223
still error ....
[
------ For reference only ---- -----------------------------------
how to run your code being given it ? :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.sun.jna.platform.WindowUtils$Holder.<clinit>(WindowUtils.java:570)
at com.sun.jna.platform.WindowUtils.getInstance(WindowUtils.java:589)
at com.sun.jna.platform.WindowUtils.setWindowAlpha(WindowUtils.java:1533)
at frametm.JFrameBackground.main(JFrameBackground.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
jar package also guide , my guide is jna-platform.jar.
under 3.3.0 version : http://download.csdn.net/detail/huxiweng/6545223
still error. .
------ For reference only ----- ----------------------------------
few months jna package
how to run your code being given it ? :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.sun.jna.platform.WindowUtils$Holder.<clinit>(WindowUtils.java:570)
at com.sun.jna.platform.WindowUtils.getInstance(WindowUtils.java:589)
at com.sun.jna.platform.WindowUtils.setWindowAlpha(WindowUtils.java:1533)
at frametm.JFrameBackground.main(JFrameBackground.java:25)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 4 more
jar package also guide , my guide is jna-platform.jar.
under 3.3.0 version : http://download.csdn.net/detail/huxiweng/6545223
still error. .
------ For reference only ---------------------------------- -----
jna.jar http://download.csdn.net/detail/huxiweng/6546089
- ----- For reference only ---------------------------------------
10th Floor huxiweng quote = quote reply : ]
jna.jar http://download.csdn.net/detail/huxiweng/6546089
references jna.jar then compile all pass, this class can not be resolved WindowUtils
[
------ For reference only ---- -----------------------------------
I see you do not run successfully Well, what you are importing a jar package ah
------ For reference only ----------------- ----------------------
I see you do not run successfully Well, what you are importing a jar package ah
Halo, two packages have !
jna.jar and jna-3.3.0-platform.jar
------ For reference only ------------------ ---------------------
I see you do not run successfully Well, what you are importing a jar package ah
Halo, two packages have !
jna.jar and jna-3.3.0-platform.jar
Sure enough , ok it. Thank you ~ ~
------ For reference only ---------------------------------------
this.setUndecorated(true); //去掉标题栏
com.sun.awt.AWTUtilities.setWindowOpaque(this,false); //this是Frame
This is not transparent enough troubles
------ For reference only ----------------------- ----------------
said that a lot of people can not find the class. . .
com.sun.awt.AWTUtilities
packages like the sun does not recommend the use of it
------ For reference only ------------------------- --------------
jdk7 comes with transparent effect ,
jdk6 recommend using JNA, AWTUtilities transparent window I can be successful only under the windows in linux to die.
------ For reference only -------------------------------------- -
Thank you , I just want to get some transparency effects, such as the top of an opaque , transparent bottom plate assembly opaque , I found swing hacks inside a case can be used to achieve this effect.
没有评论:
发表评论