Java Code Examples for java.awt.Window#getBackground()

The following examples show how to use java.awt.Window#getBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChildWindowProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testChildPropertiesWithDialogAsParent() {

        parentDialog = new Dialog((Dialog) null, "parent Dialog");
        parentDialog.setSize(WIDTH, HEIGHT);
        parentDialog.setLocation(100, 100);
        parentDialog.setBackground(Color.RED);
        parentLabel = new Label("ParentForegroundAndFont");
        parentFont = new Font("Courier New", Font.ITALIC, 15);
        parentDialog.setForeground(Color.BLUE);
        parentDialog.setFont(parentFont);

        parentDialog.add(parentLabel);
        parentDialog.setVisible(true);

        windowChild = new Window(parentDialog);
        windowChild.setSize(WIDTH, HEIGHT);
        windowChild.setLocation(WIDTH + 200, 100);
        childLabel = new Label("ChildForegroundAndFont");
        windowChild.add(childLabel);
        windowChild.setVisible(true);

        if (parentDialog.getBackground() == windowChild.getBackground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Background Color");
        }
        if (parentDialog.getForeground() == windowChild.getForeground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Foreground Color");
        }
        if (parentDialog.getFont() == windowChild.getFont()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Dialog's Font Color");
        }
    }
 
Example 2
Source File: ChildWindowProperties.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testChildPropertiesWithFrameAsParent() {

        parentFrame = new Frame("parent Frame");
        parentFrame.setSize(WIDTH, HEIGHT);
        parentFrame.setLocation(100, 400);
        parentFrame.setBackground(Color.BLUE);
        parentLabel = new Label("ParentForegroundAndFont");
        parentFont = new Font("Courier New", Font.ITALIC, 15);
        parentFrame.setForeground(Color.RED);
        parentFrame.setFont(parentFont);
        parentFrame.add(parentLabel);
        parentFrame.setVisible(true);

        frameChildWindow = new Window(parentFrame);
        frameChildWindow.setSize(WIDTH, HEIGHT);
        frameChildWindow.setLocation(WIDTH + 200, 400);
        childLabel = new Label("ChildForegroundAndFont");
        frameChildWindow.add(childLabel);
        frameChildWindow.setVisible(true);

        if (parentFrame.getBackground() == frameChildWindow.getBackground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Frame's Background Color");
        }
        if (parentDialog.getForeground() == windowChild.getForeground()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Frame's Foreground Color");
        }
        if (parentDialog.getFont() == windowChild.getFont()) {
            dispose();
            throw new RuntimeException("Child Window Should NOT Inherit "
                    + "Parent Frame's Font Color");
        }
    }
 
Example 3
Source File: OfficialApi.java    From 07kit with GNU General Public License v3.0 5 votes vote down vote up
public void setWindowOpaque(Window window, boolean isOpaque) {
	// prevent setting if not supported
	if(!isTranslucencyCapable(window.getGraphicsConfiguration()) ||
			!isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT, window.getGraphicsConfiguration().getDevice())) {
		return;
	}
	final Color background = window.getBackground();
	final int alpha = isOpaque ? OPAQUE : NOT_OPAQUE;
	window.setBackground(new Color(background.getRed(), background.getGreen(), background.getBlue(), alpha));
}
 
Example 4
Source File: WindowTranslucencyHelper.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
	 * Sets the window opaque.
	 *
	 * @param w the w
	 * @param opaque the opaque
	 */
	public static void setWindowOpaque(Window w, boolean opaque)
	{
//		//## Fix for: Issue BELNF-5, 目前因Jack Jiang手头没有Linux等测试环境,目前就暂时先让这
//		//## 些平台不支持窗口透明吧,起码先把BE LNF跑起来再说,此问题以后再彻底解决
//		if(!Platform.isWindows())
//		{
//			System.out.println(UN_WINDOWS_SORRY);
//			return;
//		}
		
		try
		{
//			com.sun.awt.AWTUtilities.setWindowOpaque(w, opaque);
			//1.6.0_u12及以后版本
			if(JVM.current().isOneDotSixUpdate12OrAfter())//JDK1_6_U10//为什么要到u12才支持?因u10里的窗口透明存在BUG 6750920
			{
				if(!isTranslucencySupported())
				{
					LogHelper.debug("Your OS can't supported translucency.");
					return;
				}
				
				//1.7.0及以后版本
				if(JVM.current().isOrLater(JVM.JDK1_7))
				{
//					if(isWindowTranslucencySupported())
					Color bgc = w.getBackground();
					//* 2012-09-22 由Jack Jiang注释:在群友机器上(win7+java1.7.0.1)的生产系统下
					//* 下使用BeautyEye有时w.getBackground()返回值是null,但为什么返回是null,Jack 没
					//* 有测出来(Jack测试都是正常的),暂且认为是其系统代码有问题吧,在此容错一下
					if(bgc == null)
						bgc = Color.black;//暂不知道用此黑色作为容错值合不合适
					Color newBgn = new Color(bgc.getRed(),bgc.getGreen(), bgc.getBlue(), opaque?255:0);
					w.setBackground(newBgn);
				}
				else
					ReflectHelper.invokeStaticMethod("com.sun.awt.AWTUtilities", "setWindowOpaque"
							, new Class[]{Window.class, boolean.class}, new Object[]{w, opaque});
			}
			else
				LogHelper.debug("您的JRE版本不支持窗口透明(需jre1.6_u12及以上版本),BeautyEye外观将不能达到最佳视觉效果哦.");
		}
		catch (Exception e)
		{
			if(BeautyEyeLNFHelper.debug)
				e.printStackTrace();
			LogHelper.debug("您的JRE版本不支持窗口透明(需jre1.6_u12及以上版本),BeautyEye外观将不能达到最佳视觉效果哦."+e.getMessage());
//			e.printStackTrace();
		}
	}