awt

calling invokeAndWait from the EDT

烂漫一生 提交于 2019-11-30 08:38:53
问题 I have a problem following from my previous problem. I also have the code SwingUtillities.invokeAndWait somewhere else in the code base, but when I remove this the gui does not refresh. If I dont remove it the error I get is: Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread at java.awt.EventQueue.invokeAndWait(Unknown Source) at javax.swing.SwingUtilities.invokeAndWait(Unknown Source) at game.player.humanplayer.model

How can I do full screen in Java on OSX

回眸只為那壹抹淺笑 提交于 2019-11-30 06:58:39
问题 I've been trying and failing to use the java full screen mode on the primary display of an OSX system. Whatever I've tried I can't seem to get rid of the 'apple' menu bar from the top of the display. I really need to paint over the entire screen. Can anyone tell me how to get rid of the menu? I've attached an example class which exhibits the problem - on my system the menu is still visible where I would expect to see a completely blank screen. import java.awt.*; import java.awt.event.*;

AWT Window Close Listener/Event

前提是你 提交于 2019-11-30 06:41:41
I am sorry if this is a n00b question, but I have spent way too long for this once I create the Window listener, window event, and everything else, how do I specify what method to invoke? Here is my code: private static void mw() { Frame frm = new Frame("Hello Java"); WindowEvent we = new WindowEvent(frm, WindowEvent.WINDOW_CLOSED); WindowListener wl = null; wl.windowClosed(we); frm.addWindowListener(wl); TextField tf = new TextField(80); frm.add(tf); frm.pack(); frm.setVisible(true); } I am trying to get a URL, and Download it, I have everything else worked out, I am just trying to get the

Swing: How to make non-rectangular windows with soft borders?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 04:56:29
问题 How could I make non-rectangular windows with soft borders in Java? Soft borders (also known as soft clipping) are borders without aliasing artifacts. I searched the web a lot and found several posts about translucent and/or non-rectangular windows. The topic "soft border" is confusing. It seems that the information I found deals with applying soft borders to component which are inside another Java components. But, can I, or can I not apply soft borders to custom shaped JWindow which is

Functional Interface(函数式接口)

夙愿已清 提交于 2019-11-30 04:40:10
什么是函数式接口(Functional Interface) 其实之前在讲Lambda表达式的时候提到过,所谓的函数式接口,当然首先是一个接口,然后就是在这个接口里面 只能有一个抽象方法 。 这种类型的接口也称为SAM接口,即Single Abstract Method interfaces。 函数式接口用途 它们主要用在Lambda表达式和方法引用(实际上也可认为是Lambda表达式)上。 如定义了一个函数式接口如下: @FunctionalInterface interface GreetingService { void sayMessage(String message); } 那么就可以使用Lambda表达式来表示该接口的一个实现(注:JAVA 8 之前一般是用匿名类实现的): GreetingService greetService1 = message -> System.out.println("Hello " + message); 关于@FunctionalInterface 注解 Java 8为函数式接口引入了一个新注解@FunctionalInterface,主要用于 编译级错误检查 ,加上该注解,当你写的接口不符合函数式接口定义的时候,编译器会报错。 正确例子 ,没有报错 : @FunctionalInterface interface

Java: use clipboard to copy-paste java objects between different instances of same application

自古美人都是妖i 提交于 2019-11-30 03:46:58
问题 I am trying to implement copy-paste of objects between different instances of same application. Currently it works only in one application (I mean, copy and paste in the same instance of application), but does not work between different instances. Copying code: // MyObject is a class of objects I want to copy/paste; // MyObjectSelection is a class that impements Transferable and ClipboardOwner interfaces Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); MyObject data =

Does AWT/Swing cancel painting operations if the monitor is off?

情到浓时终转凉″ 提交于 2019-11-30 03:01:39
问题 I am experiencing a problem with Swing that only occurs when the computer monitor is powered off, but my Swing application continues to run in the background. It seems that whenever the monitor is off, Swing/AWT cancels all painting operations, leading to a number of display issues in the GUI that are visible as soon as the monitor turns back on. For example, when I turn off the monitor using a custom JNI function and subsequently open a simple message dialog, the message dialog is blank when

Make a BufferedImage use less RAM?

一个人想着一个人 提交于 2019-11-30 02:02:12
I have java program that reads a jpegfile from the harddrive and uses it as the background image for various other things. The image itself is stored in a BufferImage object like so: BufferedImage background background = ImageIO.read(file) This works great - the problem is that the BufferedImage object itself is enormous. For example, a 215k jpeg file becomes a BufferedImag e object that's 4 megs and change. The app in question can have some fairly large background images loaded, but whereas the jpegs are never more than a meg or two, the memory used to store the BufferedImage can quickly

mixing awt and swing in GUI programming using Java

别等时光非礼了梦想. 提交于 2019-11-29 23:31:07
问题 I read on SO that mixing awt and swing is not really a good approach for GUI programming in Java. I cannot though, find any examples which does not use some awt components while using swing. For example, even when using swing, most of the example I have encountered will use awt for layout and event handling. That being said, what does it mean not to mix swing and awt in GUI programming using Java? Does it just mean not to borrow graphical widgets such as button, canvas from swing and awt at

How to center a Window in Java?

▼魔方 西西 提交于 2019-11-29 19:04:12
What's the easiest way to centre a java.awt.Window , such as a JFrame or a JDialog ? Andrew Swan From this link If you are using Java 1.4 or newer, you can use the simple method setLocationRelativeTo(null) on the dialog box, frame, or window to center it. This should work in all versions of Java public static void centreWindow(Window frame) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2); int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); } Kevin Day Note that both the