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);
window.add(label); window.setAlwaysOnTop(true); window.setBackground(new Color(0,true)); DragSource.getDefaultDragSource().addDragSourceMotionListener( new DragSourceMotionListener() {
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; }
private void resetIconAndBackground() { if (window != null) { window.setBackground(null); title.setFrame(null); } }
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); } }
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); } }
//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); } }
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) { } } } }
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); } }
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); } }
/** * 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")); } } }
ancestor.setBackground ( new Color ( 0, 0, 0, 0 ) );
setBackground( new Color(0, 0, 0, 0) ); setSize(ii.getIconWidth(),ii.getIconHeight()); setLocationRelativeTo(null);
try { Color background = new ColorUIResource(Color.decode(colors[i + 1])); window.setBackground(background); } catch (NumberFormatException e) {
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; }
window.setBackground(Color.RED); window.setPreferredSize(new Dimension(200, 200)); window.setLayout(new FlowLayout());
w.setBackground(color); w.setName(WINDOW_NAME); w.pack();
window.setBackground(Color.BLACK); window.setIgnoreRepaint(true); window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));