Tag Archives: swing

如何在JDialog上注册全局ESC键事件

大多数用户可能会有这么一个习惯:对于富客户端弹出的Dialog,习惯使用ESC将其关闭,而不是“叉掉它”。在Swing中,弹出窗口一般继承自JDialog类,但默认没有对ESC键事件做响应,下面这段代码可以完成这个功能: private static final KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); public static final String dispatchWindowClosingActionMapKey = "com.jayxu:WINDOW_CLOSING"; // any key string you like   public static void installEscapeCloseOperation(final JDialog dialog) { // any method name you like     Action dispatchClosing = new AbstractAction() {         public void actionPerformed(ActionEvent event) {     read more »

如何使用J2D将一张图片灰度化

可使用以下代码: Graphics2D g2d = source.createGraphics();   ColorSpace grayCS = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorConvertOp colorConvertOp = new ColorConvertOp(grayCS, g2d.getRenderingHints()); colorConvertOp.filter(source, source); Graphics2D g2d = source.createGraphics(); ColorSpace grayCS = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorConvertOp colorConvertOp = new ColorConvertOp(grayCS, g2d.getRenderingHints()); colorConvertOp.filter(source, source); 其中source为BufferedImage对象

How To Enable Anti-Aliased Globally Since JDK 5

I just read “Swing Hacks” and find it is that easy to enable anti-aliased since JDK 5.  Just add a one-line code listed below at the very beginning of your whole application System.setProperty("swing.aatext", "true"); System.setProperty(“swing.aatext”, “true”); That’s all

无觅相关文章插件,快速提升流量