September 15, 1998

Wrapping Text in TextArea

Question: Is there a way to wrap text that is written to the TextArea? Answer: The java.awt.TextArea class does not have built-in support for wrapping text, but you can implement line wrapping by catching keystrokeevents and tracking the current caret position and comparing it to the size of the TextArea.

Saving Panels with TextField?

Question: I am writing a presentation application and want to take a Panel and add TextFields and maybe Images to it. Is it possible to save this Panel with TextFields on it to disk and reload it later without losing the size and the text of the TextFields? Answer: As

TextField listeners

Question: I want to capture an event that signals a user’s completed update to a TextField. Answer: In general, a user will finish entering text in a TextField by pressing the enter key. This generates an ActionEvent. It sounds like that’s all you need to catch. Although if you wanted

Copy & Paste

Question: How can I copy the selected text from a TextArea to the system clipboard or paste from the system clipboard to a TextArea? Answer: Java 1.1 introduced the java.awt.datatransfer package, which implements the basic mechanisms for using the system clipboard. It defines a Clipboard class through which you can

Textediting functions in Java

Question: I’m trying to make a text editor in Java, andI want the editor to be able to make words and even pieces of words italic, bold, or underlined. It must also be able to change the color of pieces of text and the font. Is there a component that

HTML browser in Java

Question: I am tring to make a stand-alone application that can read HTML files and render them like a Web browser. How can I do this in pure Java? Answer: The Swing classes provide the ability to parse and render HTML 3.2 files. The underlying support for this functionality is

Port information

Question: I need to take a port number as input froma user. How can I check if the port numberentered by the user is free and not beingused by any program currently on his/her machine? Answer: The only way to do this in pure Java is to try to open

Setting textfield focus

Question: I have an initially disabled TextField on a frame.When the user clicks a specific button the TextField is enabled. How do I set the input focus to the TextField ? Answer: After you press the button that enables the text field, the button retains the input focus. To assign