awt

java.awt.Frame.setBackground() not working in OS X

孤街醉人 提交于 2019-12-11 01:47:27
问题 I'm trying to iron out some UI rendering bugs in my java applet in OS X, and I've hit one that I can't figure out. All the windows that we open that extend java.awt.Frame seem to ignore the setBackground() calls, and instead use the OS X default (brushed metal or gray gradient, depending on the OS version). Anything we open that extends Dialog works fine though. I tried overriding the paint() method and drawing the background color there. However, this only partially works. The background

Way to force KDE to not allow minimization of Java JDialog elements?

喜夏-厌秋 提交于 2019-12-11 01:44:01
问题 I have a Java application that uses JDialog boxes for displaying certain information. The JDialog boxes are not minimizable (and shouldn't be), but we've run into a problem specific to Linux KDE desktop (4.3.5, but I believe it probably applies to 4.x). KDE window decorators appear to be overriding Java's and are allowing minimization of JDialog boxes. Windows/Solaris/Linux (GNOME desktops) do not allow minimization of JDialog boxes, it appears to only be KDE. Is there an attribute that I am

Java Card Layout. One component in multiple cards

天大地大妈咪最大 提交于 2019-12-11 01:28:36
问题 Can one component (e.g. a JLabel ) be in multiple cards using CardLayout ? Currently it seems that the component appears only at the last card it was added to. If there is a way to do this, should I? Is it bad practice? Or is there some alternative? 回答1: You are correct that it only appears in the "last card it was added to", but that has nothing to do with CardLayout , that has to do with the fact each component can only be in one parent. From the Javadoc for java.awt.Container.addImpl

Switching JPanels

半腔热情 提交于 2019-12-11 00:41:17
问题 So I'm trying to make a basic program to learn more about java, and I'm having trouble switching screens. I wanted to have a display class that I could call in other classes to handle all the panels and such, and then make a class to build each panel. What I'm trying to do at the moment is use a button in my startmenu class to change from one panel to another using a method in the display class. Here's the code in the startmenu class: public void actionPerformed(ActionEvent e) { display

How to create background of JFrame transparent in java but keeping buttons visible?

旧街凉风 提交于 2019-12-11 00:24:48
问题 I am making my JFrame transparent by: myFrame.setUndecorated(true); myFrame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f)); It makes JFrame transparent but also lost window strip and close button. To make window appear visible I used AWTUtilities.setOpacity(this, 0.5f); but I found that this method is only available for java 6 and packaged in AWT package which is restricted in java 7. and the method is also changed in java 7 which is now Window.setOpacity(float opacity); but it does not

Painting on JFrame without extending

女生的网名这么多〃 提交于 2019-12-10 23:52:47
问题 My application is not JFrame-oriented, it just uses one for output. I just need to be able to tell it to draw a rectangle here, clear the screen now, a few hundred times. To do this, I wrote the following code in my main, which, by my understanding, should clear the entire JFrame to a nice blue background color. JFrame frame = new JFrame("Maze Master Premium Super-Deluxe V199.39"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int resolution = 20; int frameWidth = horiz * resolution;

BufferStrategy Illegal State Exception

╄→гoц情女王★ 提交于 2019-12-10 23:08:39
问题 After a few hours of trying to work this out I am stumped. I am somewhat new to Java and could use some help. The Stack Trace: java.lang.IllegalStateException: Component must have a valid peer at java.awt.Component$FlipBufferStrategy.createBuffers(Unknown Source) at java.awt.Component$FlipBufferStrategy.<init>(Unknown Source) at java.awt.Component$FlipSubRegionBufferStrategy.<init>(Unknown Source) at java.awt.Component.createBufferStrategy(Unknown Source) at java.awt.Canvas

Is the order in which KeyListeners will be called guaranteed?

谁说我不能喝 提交于 2019-12-10 23:05:00
问题 I may be missing something obvious about this in the documentation for addKeyListener, removeKeyListener, getKeyListeners or associated tutorials, but are there any guarantees about the order in which added key listeners are run? My hope is that they are run in the order in which they are added, but I don't see that this is specified anywhere. The situation I have is that I need to add a key listener to an existing Component and override the existing key listeners for particular keys. It

Trouble with mouseDragged and multiple objects

我是研究僧i 提交于 2019-12-10 21:53:47
问题 We are playing around with mouseDragged and multipleObjects. We are trying to create a board game that has 8 pieces that can be individually clicked and dragged to their respective location on the board (without using jpanel, jframe, etc). As of now we have created 8 individual pieces for the board game, however when you go to click/drag piece '2', it causes all of the pieces to come together under the top piece. Our initial solution (not shown) is to use a button to cycle between players

How to change the cursor image in Java AWT and/or Swing?

China☆狼群 提交于 2019-12-10 20:22:06
问题 I'm making a simple graphics editor (i.e a paint program ). I am not planning on anything fancy, but I do want my program to change the mouse cursor to something like a "+" or an "O" when it enters the Paint Panel. like in Photoshop or GIMP. How would I do this? I can't find anything in AWT / Swing threads on how to change the mouse cursor. 回答1: Just in case someone wants something more "fancy" than any of the default cursors: it's possible to create a custom cursor (provided the Toolkit