0
A
回答
2
我一直在关闭这个开关一段时间,但从来没有真正得到任何满意的结果。为什么?因为为了得到这个工作,你需要使窗口透明(实际上半透明),但使用本机的外观和感觉的装饰时,该窗口必须以未修饰的工作......
注:这使得利用TeamDev JNI Library and associated WinPack Library的 - 因为当我开始使用这种类型的东西,JNA仍然在它的婴儿期
import com.jniwrapper.Function;
import com.jniwrapper.Library;
import com.jniwrapper.Parameter;
import com.jniwrapper.Pointer;
import com.jniwrapper.UInt32;
import com.jniwrapper.win32.ui.Wnd;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.Window;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
public class TestDWM {
public static void main(String[] args) {
new TestDWM();
}
public TestDWM() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setBackground(new Color(0, 0, 0, 0));
TranslucentPane panel = new TranslucentPane();
frame.setContentPane(panel);
panel.setBorder(new EmptyBorder(40, 40, 40, 40));
frame.setLayout(new GridBagLayout());
JLabel label = new JLabel("I'm a banana");
label.setFont(label.getFont().deriveFont(Font.BOLD, 48f));
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true);
frame.setVisible(true);
setBlurBehind(frame);
}
});
}
public class TranslucentPane extends JPanel {
public TranslucentPane() {
setOpaque(false);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Color color = getBackground();
color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 32);
g.setColor(color);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
public static void setBlurBehind(Window window) {
Wnd wnd = new Wnd(window);
Library libDWMAPI = new Library("Dwmapi");
Function fEnableBlurBehindWindow = libDWMAPI.getFunction("DwmEnableBlurBehindWindow");
DWMBlurBehind behind = new DWMBlurBehind();
System.out.println("wnd = " + wnd);
UInt32 dwResult = new UInt32(0);
long hResult = fEnableBlurBehindWindow.invoke(
dwResult,
new Parameter[]{
wnd,
new Pointer(behind)
});
System.out.println("hResult = " + hResult);
System.out.println("dwResult = " + dwResult.getValue());
}
}
而且DWMBlurBehind
类
import com.jniwrapper.Int;
import com.jniwrapper.Parameter;
import com.jniwrapper.Pointer;
import com.jniwrapper.Structure;
import com.jniwrapper.UInt32;
import windows.WinDef;
public class DWMBlurBehind extends Structure {
public static final int DWM_BB_ENABLED = 0x1;
public static final int DWM_BB_BLURREGION = 0x2;
public static final int DWM_BB_TRANSITIONONMAXIMIZED = 0x4;
private UInt32 dwFlags;
private Int enabled;
private Pointer.Void region;
private Int transitionOnMazimized;
public DWMBlurBehind() {
dwFlags = new UInt32(DWM_BB_ENABLED);
enabled = new Int(WinDef.TRUE);
transitionOnMazimized = new Int(WinDef.TRUE);
region = new Pointer.Void();
init(new Parameter[]
{
dwFlags,
enabled,
region,
transitionOnMazimized
});
}
public long getFlags() {
return dwFlags.getValue();
}
}
,说了这么多,如果你没有对UI使用本机外观关心和感觉,你可以创建一个装饰框(它使用外观和感觉的装饰)作为demonstrated here
相关问题
- 1. 带有模糊透明背景的JFrame
- 2. 透明模糊的背景
- 3. 透明模糊背景
- 4. 透明JFrame背景
- 5. 在jframe中模糊背景创建透明矩形
- 6. 模糊和透明的按钮背景
- 7. 类似iOS的半透明模态,模糊背后的背景
- 8. 如何让JFrame透明?
- 9. 透明背景JFrame Linux上的动画
- 10. 如何让TreeView背景透明?
- 11. 如何让链接背景透明?
- 12. 如何让背景变得透明?
- 13. 如何让UIPageViewController背景半透明?
- 14. Java:如何让容器的Jscrollpane背景不透明? (即透明)
- 15. 模糊半透明窗体的背景(如Aero玻璃)
- 16. 模拟透明背景
- 17. 如何减少JFrame背景颜色的不透明度
- 18. 如何使背景透明?
- 19. 如何cvCopy背景透明?
- 20. 活动与透明的背景和模糊过滤
- 21. JDialog具有透明背景,模糊了底下的东西
- 22. 创建一个半透明的模糊背景WPF
- 23. 创建模糊的透明背景效果
- 24. 如何使用Twitter Bootstrap使模糊背景模糊背景?
- 25. 让班级的背景颜色透明?
- 26. 无法让我的DialogFragment背景透明
- 27. 透明背景
- 28. java:如何将透明渐变背景添加到JFrame
- 29. 如何使JFrame背景和JPanel透明,仅显示图像
- 30. 背景透明度和模糊处理另一幅图像
可能重复[在jframe中模糊背景中创建透明矩形](http://stackoverflow.com/questions/23215415/create-an-transparent-rectangle-over-blurred-background-in-jframe) – gtgaxiola 2015-03-02 18:51:58
@gtgaxiola我看了一下在我发布我的问题之前在那个职位。如果您仔细阅读我的问题,我想添加模糊效果而不在背景中添加任何图像。但是您提到的帖子是为了修复该特定组件并使背景图像模糊。 – Alex 2015-03-02 19:12:05
一般来说,没有。你“可能”能够使用JNI/JNA来完成它,但是随后你会遇到一整套新的问题,因为核心API被设计来处理它... – MadProgrammer 2015-03-02 20:35:11