java.awt.Window.setBackground()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中java.awt.Window.setBackground()方法的一些代码示例,展示了Window.setBackground()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.setBackground()方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:setBackground

Window.setBackground介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Window w=new Window(null)
{
 @Override
 public void paint(Graphics g)
 {
  final Font font = getFont().deriveFont(48f);
  g.setFont(font);
  g.setColor(Color.RED);
  final String message = "Hello";
  FontMetrics metrics = g.getFontMetrics();
  g.drawString(message,
   (getWidth()-metrics.stringWidth(message))/2,
   (getHeight()-metrics.getHeight())/2);
 }
 @Override
 public void update(Graphics g)
 {
  paint(g);
 }
};
w.setAlwaysOnTop(true);
w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setBackground(new Color(0, true));
w.setVisible(true);

代码示例来源:origin: stackoverflow.com

window.add(label);
window.setAlwaysOnTop(true);
window.setBackground(new Color(0,true));
DragSource.getDefaultDragSource().addDragSourceMotionListener(
new DragSourceMotionListener() {

代码示例来源:origin: com.fifesoft.rtext/fife.common

public boolean setOpaque(Window w, boolean opaque) {
  if (!opaque && !isTranslucencySupported(true)) {
    return false;
  }
  if (opaque) {
    w.setBackground(Color.white);
  }
  else {
    w.setBackground(new Color(0,0,0, 0));
  }
  return true;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/skinlf

private void resetIconAndBackground() {
 if (window != null) {
  window.setBackground(null);
  title.setFrame(null);
 }
}

代码示例来源:origin: net.java.dev.jna/jna-platform

private void setBackgroundTransparent(Window w, boolean transparent, String context) {
    JRootPane rp = w instanceof RootPaneContainer
      ? ((RootPaneContainer)w).getRootPane() : null;
    if (transparent) {
      if (rp != null) {
        rp.putClientProperty(TRANSPARENT_OLD_BG, w.getBackground());
      }
      w.setBackground(new Color(0,0,0,0));
    }
    else {
      if (rp != null) {
        Color bg = (Color)rp.getClientProperty(TRANSPARENT_OLD_BG);
        // If the old bg is a
        // apple.laf.CColorPaintUIResource, the window's
        // transparent state will not change
        if (bg != null) {
          bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha());
        }
        w.setBackground(bg);
        rp.putClientProperty(TRANSPARENT_OLD_BG, null);
      }
      else {
        w.setBackground(null);
      }
    }
    fixWindowDragging(w, context);
  }
}

代码示例来源:origin: net.java.dev.jna/platform

private void setBackgroundTransparent(Window w, boolean transparent, String context) {
    JRootPane rp = w instanceof RootPaneContainer
      ? ((RootPaneContainer)w).getRootPane() : null;
    if (transparent) {
      if (rp != null) {
        rp.putClientProperty(TRANSPARENT_OLD_BG, w.getBackground());
      }
      w.setBackground(new Color(0,0,0,0));
    }
    else {
      if (rp != null) {
        Color bg = (Color)rp.getClientProperty(TRANSPARENT_OLD_BG);
        // If the old bg is a
        // apple.laf.CColorPaintUIResource, the window's
        // transparent state will not change
        if (bg != null) {
          bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha());
        }
        w.setBackground(bg);
        rp.putClientProperty(TRANSPARENT_OLD_BG, null);
      }
      else {
        w.setBackground(null);
      }
    }
    fixWindowDragging(w, context);
  }
}

代码示例来源:origin: stackoverflow.com

//other imports
import java.awt.Toolkit;

public class test
{
  public static void main(String[] args) 
  {
    Window wnd = new Window(new Frame());

    //Of course this set the window 100 px to the right
    // and 100 to the bottom
    wnd.setLocation(100, 100);

    //You use the Toolkit class!!
    //Now your window has the same size of your screen!!
    wnd.setSize(Toolkit.getDefaultToolkit().getScreenSize());

    wnd.setBackground(Color.red);
    wnd.setVisible(true);
  }
}

代码示例来源:origin: com.jtattoo/JTattoo

public static void setTranslucentWindow(Window wnd, boolean translucent) {
  if (isTranslucentWindowSupported()) {
    if (JTattooUtilities.getJavaVersion() >= 1.7) {
      if (translucent) {
        if (wnd.getBackground() == null || !wnd.getBackground().equals(new Color(0, 0, 0, 0))) {
          wnd.setBackground(new Color(0, 0, 0, 0));
        }
      } else {
        if (wnd.getBackground() == null || !wnd.getBackground().equals(new Color(0, 0, 0, 0xff))) {
          wnd.setBackground(new Color(0, 0, 0, 0xff));
        }
      }
    } else if (JTattooUtilities.getJavaVersion() >= 1.6010) {
      try {
        Class clazz = Class.forName("com.sun.awt.AWTUtilities");
        Class classParams[] = {Window.class, Boolean.TYPE};
        Method method = clazz.getMethod("setWindowOpaque", classParams);
        if (translucent) {
          Object methodParams[] = {wnd, Boolean.FALSE};
          method.invoke(wnd, methodParams);
        } else {
          Object methodParams[] = {wnd, Boolean.TRUE};
          method.invoke(wnd, methodParams);
        }
      } catch (Exception ex) {
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.*;
public class test extends JWindow{
  public test(){
    super();
    this.setSize(500, 400);
    this.setLocation(50, 50);

    setBackground(new Color(0,0,0,0)); // this is the critical line - that fourth 0 represents alpha (or opacity)

    setAlwaysOnTop( true );  // keeps it in the foreground so you don't click away from it - note that clicks on the transparent part DO pass through to the desktop, at least on Lion

    JLabel testLabel = new JLabel("Floating text hah");
    this.add(testLabel);

  }
  public static void main(String[] args){
    System.out.println("Sup");
    test t = new test();
    t.setVisible(true);
  }
}

代码示例来源:origin: stackoverflow.com

public class test {
 public static void main(String[] args) {
   Window wnd = new Window(new Frame());
   //wnd.setLocation(100, 100);
   wnd.setSize(wnd.getToolkit().getScreenSize());
   wnd.setBackground(Color.red);
   wnd.setVisible(true);
   }
 }

代码示例来源:origin: khuxtable/seaglass

/**
 * Tries to make the given {@link Window} non-opqaue (transparent) across
 * platforms and JREs. This method is not guaranteed to succeed, and will
 * fail silently if the given {@code Window} cannot be made non-opaque.
 *
 * <p>This method is useful, for example, when creating a HUD style window
 * that is semi-transparent, and thus doesn't want the window background to
 * be drawn.</p>
 *
 * @param window the {@code Window} to make non-opaque.
 */
public static void makeWindowNonOpaque(Window window) {
  if (PlatformUtils.isJava6()) {
    // on non-mac platforms, try to use the facilities of Java 6 update 10.
    if (!PlatformUtils.isMac()) {
      quietlyTryToMakeWindowNonOqaque(window);
    } else {
      window.setBackground(UIManager.getColor("seaGlassTransparent"));
    }
  }
}

代码示例来源:origin: stackoverflow.com

ancestor.setBackground ( new Color ( 0, 0, 0, 0 ) );

代码示例来源:origin: stackoverflow.com

setBackground( new Color(0, 0, 0, 0) );
setSize(ii.getIconWidth(),ii.getIconHeight());
setLocationRelativeTo(null);

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/skinlf

try {
 Color background = new ColorUIResource(Color.decode(colors[i + 1]));
 window.setBackground(background);
} catch (NumberFormatException e) {

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

public static ImagePanel createSplashImagePanel( String strImage )
{
 ImagePanel imagePanel = new ImagePanel( strImage );
 imagePanel.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
 Window splash =
  new Window( new Frame() )
  {
   public void update( Graphics g )
   {
    this.paint( g );
   }
  };
 splash.setBackground( new Color( 0, 0, 0, 0 ) );
 splash.setLayout( new BorderLayout() );
 splash.add( BorderLayout.CENTER, imagePanel );
 splash.pack();
 EditorUtilities.centerWindowInFrame( splash, splash );
 splash.setVisible( true );
 imagePanel.repaintNow();
 return imagePanel;
}

代码示例来源:origin: stackoverflow.com

window.setBackground(Color.RED);
window.setPreferredSize(new Dimension(200, 200));
window.setLayout(new FlowLayout());

代码示例来源:origin: net.java.dev.jna/jna-platform

w.setBackground(bg);

代码示例来源:origin: net.java.dev.jna/platform

w.setBackground(bg);

代码示例来源:origin: abbot/abbot

w.setBackground(color);
w.setName(WINDOW_NAME);
w.pack();

代码示例来源:origin: com.b3dgs.lionengine/lionengine-core-awt

window.setBackground(Color.BLACK);
window.setIgnoreRepaint(true);
window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));

相关文章

Window类方法