在SWT中嵌入JavaFX的一个问题

jdgdf566 2014-01-21 06:19:03

import javafx.embed.swt.FXCanvas;
import javafx.scene.Parent;
import javafx.scene.Scene;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
*
* @author Administrator
*/
public class NewMain {

static Scene scene;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.CLOSE | SWT.ON_TOP);
//shell.setAlpha(100);
shell.setSize(500, 500);
//shell.setBackgroundMode(SWT.INHERIT_FORCE);
//shell.setBackground(new Color(display, 255, 0, 0));
//shell.setLayout(new FillLayout());
//-------------------------------
FXCanvas fXCanvas = new FXCanvas(shell, SWT.NONE);
//<Scene
Parent root = new Parent() {
};
scene = new Scene(root, 500, 500);
scene.setFill(javafx.scene.paint.Color.color(0, 0, 0, 0));
fXCanvas.setScene(scene);
fXCanvas.setSize(500, 500);
//Scene>
//--------------------------------
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

}

我需要让场景scene的背景透明,即第33行:
scene.setFill(javafx.scene.paint.Color.color(0, 0, 0, 0));
但是却是黑色。
...全文
315 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
solomon5926 2014-01-23
  • 打赏
  • 举报
回复
引用 7 楼 jdgdf566 的回复:
[quote=引用 6 楼 solomon5926 的回复:] 这个类javax.swing.JComponent下面的一个方法setOpaque,在api中的解释如下: public void setOpaque(boolean isOpaque) If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent. Parameters: isOpaque - true if this component should be opaque 这个是设置透明效果的方法,运用的话要自己灵活运用,你可以先去试试
必须操作背景颜色,模糊度会是容器中的所有东西都半透明。[/quote] 哦,没看你导入的包,这个包我没用过,你可以查一下和这个类有关的文档
jdgdf566 2014-01-23
  • 打赏
  • 举报
回复
引用 6 楼 solomon5926 的回复:
这个类javax.swing.JComponent下面的一个方法setOpaque,在api中的解释如下: public void setOpaque(boolean isOpaque) If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent. Parameters: isOpaque - true if this component should be opaque 这个是设置透明效果的方法,运用的话要自己灵活运用,你可以先去试试
必须操作背景颜色,模糊度会是容器中的所有东西都半透明。
solomon5926 2014-01-23
  • 打赏
  • 举报
回复
这个类javax.swing.JComponent下面的一个方法setOpaque,在api中的解释如下: public void setOpaque(boolean isOpaque) If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent. Parameters: isOpaque - true if this component should be opaque 这个是设置透明效果的方法,运用的话要自己灵活运用,你可以先去试试
jdgdf566 2014-01-23
  • 打赏
  • 举报
回复
引用 4 楼 huangjiu1990 的回复:
是不是shell的背景色
不是
huangjiu1990 2014-01-23
  • 打赏
  • 举报
回复
是不是shell的背景色
jdgdf566 2014-01-22
  • 打赏
  • 举报
回复
沉了?不知道就说声不知道也行,没有人看见帖子是怎么的?
jdgdf566 2014-01-21
  • 打赏
  • 举报
回复
怎么这么冷清,都忙着放假吗?

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧