awt

JButtons re-enable themselves after being disabled

I have an array of JButtons which form a keypad interface. After six numbers are entered I want to disable the keypad so that no further numbers can be entered by the user. I have written the code and the buttons do disable until the mouse hovers above any of them, then the buttons seem to re-enable themselves and run actionEvents added...

Serialize a java.awt.geom.Area

Hi all, I have the need to serialize an Area object (java.awt.geom.Area) in a socket. However it doesn't seem to be serializable. Is there a way to do such thing? Maybe by converting it into a different object? Thanks in advance ...

How can I find all the supported weights of a Font in Java?

How can I find all the available font weights for a given font in Java? The TextAttribute for font weight lists 11 different weight constants, way more than just Font.PLAIN and Font.BOLD. I'd like to know which ones actually exist for a given font family, so I can make sure I'm only using weights for which a font face exists. The getA...

algorithim for simple colision detection in Java

I'm not very experienced with Java, just started a couple weeks ago, but I have a simple applet that has two user controlled balls, drawn through java.awt and I need a way to detect a collision with between them. I have an algorithm for detecting collision with the walls: while (true){ if (xPositon > (300 - radius)){ ...

Default Button after dispose and setVisible

Hi, given the following code: public class DialogTest implements ActionListener { public static void main(String[] args) {DialogTest g = new DialogTest();} public DialogTest() { JButton b1 = new JButton("Button A"); b1.addActionListener(this); JDialog d = new JDialog(); d.setDefaultCloseOperation(JDialog.DISPOSE_ON...

PNGException "crc corruption" when attempting to create ImageIcon objects from ZIP archive

I've got a ZIP file containing a number of PNG images that I am trying to load into my Java application as ImageIcon resources directly from the archive. Here's my code: import java.io.*; import java.util.Enumeration; import java.util.zip.*; import javax.swing.ImageIcon; public class Test { public static void main( String[] args ) ...

How to get Color object in java from css-style string which describes color?

For example, I have strings #0f0, #00FF00, green and in all cases I want to transform them to Color.GREEN. Are there any standard ways or maybe some libraries have necessary functionality? ...

How to use my trackpad for horizontal mousewheel scrolling in a Java AWT ScrollPane

Like many modern mice and trackpads, my laptop supports vertical and horizontal scrolling. It's an addictive feature once you get used to it. I simply want my Java apps to support horizontal scrolling via the trackpad/mousewheel, but everywhere I search it seems that this is not possible in Java. I really want someone to tell me that ...

Java - FontMetrics without Graphics

Hello! How to get FontMetrics without use Graphics ? I want to get FontMetrics in constructor, now I do this way: BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); FontMetrics fm = bi.getGraphics().getFontMetrics(font); int width = fm.stringWidth(pattern); int height = fm.getHeight(); ...

Double Buffering with awt

Is double buffering (in java) possible with awt? Currently, I'm aware that swing should not be used with awt, so I can't use BufferStrategy and whatnot (I already have some code written in awt that I don't want to rewrite in swing). If double buffering is possible with awt, do I have to write the buffer by hand? Unlike swing, awt doesn'...

Is it safe to synchronize java.awt.Container.paint(Graphics g)?

I'm using some 3rd party AWT components in a desktop application. The component's layout is changed within the paint() method, and this causes some very strange behaviour. This appears to be fixed by adding the synchronized keyword to the paint() method, but is this a safe thing to do? ...

getBounds vs getBounds2D

Hello World, While reading the Java documentation on a Polygon, i discovered there is a getBounds method and a getBounds2D method. It was noted that the first one was less accurate than the second one. I was wondering what exactly is meant by 'less accurate'? Does getBounds return a false value or is it about 256 vs 256.3 (example)? Or...

Cannot get right height of text in java.awt.BufferdImage/Graphics2D

Im creating a servlet that renders a jpg/png with a given text. I want the text to be centered on the rendered image. I can get the width, but the height i'm getting seems to be wrong Font myfont = new Font(Font.SANS_SERIF, Font.BOLD, 400); BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); Graphics2D g = i...

AWT Textfield behaves weird with MicroSoft JVM

Hi, I am facing a weird problem when using MicroSoft JVM to run my Applet. I have an AWT panel with 4 textfields which is added to a dialog box. Everything goes fine until I enter a decimal value into the textfield and close the dialog box. When i reopen the dialog box the textfield inside the panel with all the decimal digits (entered...

Help with setting up panels in Java

I'm new to Java awt, so I am having trouble with setting up panels. I have one giant panel, which needs to hold 3 panels inside (photo is attached at the bottom). One will go on top(1), second one will be in the middle(3), and third goes on the bottom(2). Any remaining space has to be divided equally between (1)/(3) and (3)/(2). Also, th...

Java: How to display a multi-line ToolTip with AWT?

Hi, I wrote an application and now I'm making a tray-icon. Now I want to set a multi-line tooltiptext to the tray-icon. But I don't know how. I know how to do this with Swing: component.setToolTipText("<html>Line 1<br>Line2</html>"); But this doesn't work with AWT. Also serarating lines by \n doesn't work. I'm running on linux: Ubu...

Making a checkerboard-style with graphics (java applet)

OK so, I am making an applet that paints 32x32 square tiles (to make a map) and my problem is that they are going diagonally when I want them to go 8 by 8 (hence the way the array is shaped 8 by 8). So... how do I fix this? Thanks. Anyway, since the code bbcode is being a butthead... here is the pastebin URL :-) http://www.danflow.past...

Making your class an event source in Java

I'm making a custom button in Java that has two states, mousePressed, and mouseReleased. At the same time, if I wanted to reuse this button, so that other event listeners can register with it, are these the appropriate steps I should do (This is a hw assignment so although a JButton could be used, I think we are trying to show that we c...

Creating ActionEvent object for CustomButton in Java

For a hw assignment, we were supposed to create a custom button to get familiar with swing and responding to events. We were also to make this button an event source which confuses me. I have an ArrayList to keep track of listeners that would register to listen to my CustomButton. What I am getting confused on is how to notify the lis...

Malformed Farsi characters on AWT

Hi As i started programming by jdk6, i had no problem in text components neither in awt nor in swing. But for labels or titles of awt components, yes : I couldn't have Farsi characters displayable on AWTs just as simple as Swing by typing them into the source code. lets check this SSCCE : import javax.swing.*; import java.awt.*; imp...