Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
No reason to wait
Agenda
Decoration with JLayer Translucent and shaped windows Mixing heavy and lightweight components
JLayer
Component decorator Based on JxLayer http://java.net/projects/jxlayer project
JFrame f = new JFrame(); JPanel panel = createPanel(); LayerUI<JPanel> ui = new CustomLayerUI(); JLayer<JPanel> layer = new JLayer<JPanel>(panel, ui); f.getContentPane().add (layer);
JLayer in action
public class CustomLayerUI extends LayerUI { @Override public void paint(Graphics g, JComponent c) { // paint the component itself super.paint(g, c); // decorate component } }
JLayer: How to
Requires repaint on update of underlying components
Not recommended for frequently updated components
May be used instead of GlassPane to grey out selected UI component and suppress events
The only UI component is freezed on error instead of the whole frame
Per-Pixel translucency
window might contain pixels with arbitrary alpha values between and including 0.0 and 1.0
Per-Pixel transparency
each pixel is either completely opaque or completely transparent
Window translucensy
Check whether the feature is supported
GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsDevice.WindowTranslucency type = gd.isWindowTranslucencySupported(type)
// Java 6: // AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency)
Window must NOT be in full screen mode In Java 6 the translucency might not be supported for decorated windows
Per-pixel: PERPIXEL_TRANSLUCENT
JFrame.setBackground(new Color(R, G, B, alpha)), 0 < alpha < 255 Java 6: AWTUtilities.setWindowOpaque(win, false); same as alpha = 0
Throws exception if window is decorated!
Lightweight component
Reuses native window of its closest heavyweight ancestor Located in java.swing package: JButton, JLabel
Mixing Tips
Use the SIMPLE_SCROLL_MODE mode if JScrollPane contains heavyweight component For mixing a non-rectangular lightweight component with a heavyweight component
AWTUtilities.setComponentMixingCutoutShape( Component component, Shape shape)
Mixing limitations
Translucent lightweight components are not supported. Heavyweight components will NOT be visible through translucent pixels Anti-aliased (smooth) shapes are not supported Heavyweight components must have valid peer, i.e. must be created by the process which have created the frame Key events of InputMap might not work correctly when components are overlapped
Thank you!
Questions?