일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- jsr 296
- PLSQL
- oracle
- PHP
- Ajax
- Eclipse
- JSON
- phonegap
- GPS
- jQuery
- 선택적조인
- Android
- sencha touch
- 전자정부프레임워크
- JDOM
- node.js
- tomcat
- ibsheet
- swingx
- Struts
- MySQL
- WebLogic
- dock
- MFC
- iBATIS
- 가우스
- rowspan
- Google Map
- appspresso
- Spring
Archives
- Today
- Total
Where The Streets Have No Name
disabled-glass-pane 본문
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import util.ComponentUtil;
public class DisabledGlassPane extends JComponent implements KeyListener {
private final static Border MESSAGE_BORDER = new EmptyBorder(10, 10, 10, 10);
private JLabel message = new JLabel();
public DisabledGlassPane() {
// Set glass pane properties
setOpaque(false);
Color base = UIManager.getColor("inactiveCaptionBorder");
Color background = new Color(base.getRed(), base.getGreen(), base.getBlue(), 128);
setBackground(background);
setLayout(new GridBagLayout());
// Add a message label to the glass pane
add(message, new GridBagConstraints());
message.setOpaque(false); //배경을 투명하게
message.setBorder(MESSAGE_BORDER);
JButton closeBtn = ComponentUtil.createButton("X", 25, 25);
closeBtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
deactivate();
}
});
add(closeBtn);
// Disable Mouse, Key and Focus events for the glass pane
addMouseListener(new MouseAdapter() {
});
addMouseMotionListener(new MouseMotionAdapter() {
});
addKeyListener(this);
setFocusTraversalKeysEnabled(false);
}
/*
* The component is transparent but we want to paint the background to give
* it the disabled look.
*/
@Override
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getSize().width, getSize().height);
}
/*
* The background color of the message label will be the same as the
* background of the glass pane without the alpha value
*/
@Override
public void setBackground(Color background) {
super.setBackground(background);
Color messageBackground = new Color(background.getRGB());
message.setBackground(messageBackground);
}
//
// Implement the KeyListener to consume events
//
public void keyPressed(KeyEvent e) {
e.consume();
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
e.consume();
}
/*
* Make the glass pane visible and change the cursor to the wait cursor
*
* A message can be displayed and it will be centered on the frame.
*/
public void activate(String text) {
if (text != null && text.length() > 0) {
message.setVisible(true);
message.setText(text);
message.setFont(new Font("Tahoma", Font.BOLD, 12));
message.setForeground(getForeground());
} else {
message.setVisible(false);
}
setVisible(true);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
requestFocusInWindow();
}
/*
* Hide the glass pane and restore the cursor
*/
public void deactivate() {
setCursor(null);
setVisible(false);
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import util.ComponentUtil;
import org.pushingpixels.substance.api.skin.SubstanceNebulaLookAndFeel;
public class Demo1 extends JFrame{
private JFrame self;
public Demo1() {
setTitle("block frame demo");
setSize(400, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
self = this;
}
public void createComponent(){
setLayout(new BorderLayout());
JPanel pane = ComponentUtil.createPanel();
pane.setBackground(Color.red);
add(pane, BorderLayout.CENTER);
Box box = ComponentUtil.createBoxPanel();
add(box, BorderLayout.SOUTH);
box.add(Box.createHorizontalGlue());
JButton startBtn = ComponentUtil.createButton("시작");
box.add(startBtn);
startBtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
DisabledGlassPane glassPane = new DisabledGlassPane();
JRootPane rootPanel = self.getRootPane();
rootPanel.setGlassPane(glassPane);
glassPane.activate("Please Wait...");
}
});
box.add(Box.createRigidArea(new Dimension(10, 0)));
JButton stopBtn = ComponentUtil.createButton("정지");
box.add(stopBtn);
stopBtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
DisabledGlassPane glassPane = (DisabledGlassPane)self.getRootPane().getGlassPane();
glassPane.deactivate();
}
});
box.add(Box.createHorizontalGlue());
}
public void visible(){
setVisible(true);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(new SubstanceNebulaLookAndFeel());
Demo1 pane = new Demo1();
pane.createComponent();
pane.visible();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}