Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using GlassPane for Sheet-Like "dialogs"



Hi,

I am experimenting with using the GlassPane for a Sheet-Like behavior.
This seems to work pretty well, but I have problems moving the focus via Tab-Key.
I already tried many different options using the FocusManager.

Is this possible at all?
Has anyone an idea?

Regards,

Alex

Here some sample-code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class GlassPaneDialog extends JPanel implements MouseListener {

private static GlassPaneDialog _instance = new GlassPaneDialog();
private JPanel _content = new JPanel();
private int _width = 600;
private int _height = 450;

public static GlassPaneDialog getInstance() {
return _instance;
}

private GlassPaneDialog() {
MainWindowController.instance().getWindow().setGlassPane(this); // Adding the GlassPane to my MainWindow
addMouseListener(this);
setOpaque(false);
add(_content);

Dimension size = new Dimension(_width, _height);

_content.setLocation(getXpos(), 0);
_content.setMinimumSize(size);
_content.setMaximumSize(size);
_content.setPreferredSize(size);
_content.setLayout(new FlowLayout());
_content.setOpaque(false);
}

public void show(JComponent c) {
_content.removeAll();
_content.add(c);
_content.updateUI();

Dimension d = c.getPreferredSize();
_width = d.width + 50;
_height = d.height + 50;

MainWindowController.instance().getWindow().getContentPane().setFocusabl e(false);
FocusManager.getCurrentManager().setGlobalCurrentFocusCycleRoot(c);
FocusManager.getCurrentKeyboardFocusManager().setGlobalCurrentFocusCycle Root(c);
setVisible(true);
}

private int getXpos() {
Dimension size = getSize();
int xpos = (size.width - _width) / 2;
return xpos;
}

public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));

int xpos = getXpos();

g2.setColor(new Color(255, 255, 255));
g2.fillRect(xpos, 0, _width, _height);
g2.setColor(Color.black);
g2.drawRect(xpos, 0, _width, _height);

g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
super.paint(g2);
g2.dispose();
}

public void mouseClicked(MouseEvent e) {
Toolkit.getDefaultToolkit().beep();
e.consume();
}

public void mousePressed(MouseEvent e) {
e.consume();
}

public void mouseReleased(MouseEvent e) {
e.consume();
}

public void mouseEntered(MouseEvent e) {
e.consume();
}

public void mouseExited(MouseEvent e) {
e.consume();
}
}

Alexander Lohse
(Entwicklungsleitung & Projektmanagement)

WebJazz Internet Suite
Human Touch Medienproduktion GmbH
Am See 1
17440 Klein Jasedow
Deutschland

Tel (0049) 38374-752-11
Fax (0049) 38374-752-23
e-mail email@hidden
Internet http://www.webjazz.de

_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.