Text 1 « Development « Java Swing Q&A





1. Custom swing component - Turning a node into text    stackoverflow.com

I'm writing a custom swing component (something completely new, but think JTree or JList). I'm trying to follow the general design of JTree, JTable, JList etc for consistency (I've also seen ...

2. Swing components : vertical text question    stackoverflow.com

If I have a button like the one in this image : http://www.freeimagehosting.net/image.php?4cd775814c.png how could I make the text display itself vertically ? As in

j
B
u
t
t
o
n
1
I would like to know how to do ...

3. Can a text widget show overflow with the "..." in the middle of the text instead of the end?    stackoverflow.com

I have a JComboBox which contains an MRU list combo-box and a for a directory tree panel. Together, the two form the left hand panel of my GUI (the MRU ...

4. Copying selected text to a Swing Java app?    stackoverflow.com

My goal is assign a global hotkey (JIntellitype, JXGrabKey) that would pass an arbitrary selected text to a java app. The initial plan is to utilize the java.awt.Robot to emulate Ctrl-C keypress ...

5. JComponent not displaying text - Swing is pwning me!    stackoverflow.com

everyone, I'm a High School AP Computer Science student doing an independent study project in Java. I have chosen to write an application for beginning piano students in which the computer displays ...

6. Looking for an efficient Java Swing based console    stackoverflow.com

I'm looking for a highly efficient Swing Java component which I can just plug into my application UI. I already tried using the classes within Swing such as JTextArea with no ...

7. NullPointerException in javax.swing.text.SimpleAttributeSet.addAttribute    stackoverflow.com

Has anyone ever seen an exception like this (with version 1.6.0_11 of the JVM)?:

ERROR: java.lang.NullPointerException: null
    at java.util.Hashtable.put(null:-1)
    at javax.swing.text.SimpleAttributeSet.addAttribute(null:-1)
    at javax.swing.text.SimpleAttributeSet.addAttributes(null:-1)
 ...

8. Insert one DefaultStyledDocument into another DefaultStyledDocument    stackoverflow.com

I want to insert one DefaultStyledDocument into another DefaultStyledDocument. How do I do this? I know of this method:

AbstractDocument.insertString(int offs,
          ...

9. DefaultStyledDocument.styleChanged(Style style) may not run in a timely manner?    stackoverflow.com

I'm experiencing an intermittent problem with a class that extends javax.swing.text.DefaultStyledDocument. This document is being sent to a printer. Most of the time the formatting of the document looks ...





10. Netbeans building GUI; how do I disable Netbeans from disallowing me to edit text?    stackoverflow.com

I find it annoying that Netbeans tries to disable editing the source code whenever I use the GUI builder utility. I have searched in Google but could not find an ...

11. GUI and text mode - how to detect    stackoverflow.com

First of all, sorry my english, as is not my natural language.
I need my Java program to have 2 interfaces, GUI and text mode.
So that, if I run it in windows ...

12. Pure Java text interface for a roguelike game    stackoverflow.com

OK, this is going to sound like a crazy idea - but I'm interested in emulating a 1980s style roguelike game text interface in pure Java, i.e. using Swing ...

13. IllegalAccessError when trying instanceof against AbstractDocument.UndoRedoDocumentEvent from javax.swing.text    stackoverflow.com

In the source of javax.swing.text.DefaultCaret.Handler.insertUpdate(DocumentEvent) I found the following lines (starting at line 1685):

if (e instanceof AbstractDocument.UndoRedoDocumentEvent) {
    setDot(offset + length);
    return;
}
But when I try ...

14. javax.swing.text.ElementIterator weird behavior    stackoverflow.com

I'm getting a weird behavior with javax.swing.text.ElementIterator(). It never shows all elements, and it shows a different amount of elements depending on what type of ParserCallback I use. The test below ...

15. How to read last word or last line in DocumenListener    stackoverflow.com

I implement DocumentListener for JEditorPane ( need help with method insertUpdate(DocumentEvent e) ). How to read last word or last line (lines are separated by '\n' and words are separated by ...

16. Code/text folding in SWING    stackoverflow.com

I'm looking for a way to provide 'text folding' capabilities to a swing JTextArea or JTextPane More specifically, I want to add a block of data in a text component and I ...





17. Best practice for displaying text in Java?    stackoverflow.com

I'm completing a university assignment in java. It consists of some inputs, a block of text and a graph dependent on the inputs. In my course I've been taught to display text ...

18. HTML formatted text in Swing components dont show up    stackoverflow.com

I have recently came upon odd situation; HTML formatted text in my Swing components do not show up. I have searched for similar questions, and found one, but it does ...

19. Textfile search from GUI    stackoverflow.com

Ok so i have made a search function using scanner in console, but i would now like to create a search function from my GUI. When text is entered into a ...

20. What is the best way to make clickable text in java?    stackoverflow.com

This is for an application so I don't want a hyperlink. I first tried using a Jbutton without all of border/background stuff and then hooking up an actionListener to it but ...

21. Write to text file through a java GUI    stackoverflow.com

I have created a java GUI that works as a 6-question questionnaire. For each of the six question, I have 4 choices , i, ii, iii, iv for the user to ...

22. (JAVA) Comparing a word entered by a user with another word contained in a text file    stackoverflow.com

I'd like to verify if my text file already contains a word entered by a user in a textfield. When the user clicks on Validate if the word is already in ...

23. Java text component calculate its own preferred size    stackoverflow.com

I am making a customised swing component and I have hit a problem. I want a simple text display (like a jlabel) that changes colour over time. Currently I have extended ...

24. Which text component to use?    stackoverflow.com

I am making a simple chat application and I am trying to find out which text component is more appropriate to use.The component will need to support coloured text , provide ...

25. logging to swing application and console + writing to a text file the result.    stackoverflow.com

I have a program that can run either by a Swing Application or a Command-Line My question is this: How can I avoid the following code:

String message = "performing task #1; ...

26. Subclass javax.swing.text.html.TableView    forums.netbeans.org

Hello! I'm working on some html editor and I want to add more functionality to the tables view... I just dont know if the best way to do it is inherit the TableView class and add my custom methods or is there a better way to recive mouse events over tables. Please, if someone could give me a hand on this, ...

27. Netbeans deleted the text from my GUI    forums.netbeans.org

I spent over a week designing the layout for components for my GUI. I had everything where I wanted and the actual text in place for each of my components. A few hours ago I finally finished changing the default variable names to names that I can actually actually follow. I shutdown Netbeans and took a break. Then about an hour ...

28. java.text    coderanch.com

29. converting text to a double    coderanch.com

30. Formatting text for AWT List component - Tricky!    coderanch.com

Hi all, I am using JDK 1.1.8 for an Applet development. To preserve the look and feel, I need to use variable width fonts with the AWT List components. I can't use fixed width fonts. A List cannot have multiple columns, so I am concatenating the two Strings (with spaces between them for an offset). The problem is that I can't ...

31. how to hidden text ?    coderanch.com

public void setEchoChar(char c) Sets the echo character for this text field. An echo character is useful for text fields where user input should not be echoed to the screen, as in the case of a text field for entering a password. Setting echoChar = 0 allows user input to be echoed to the screen again.

32. HTML text on SWING components    coderanch.com

33. Need to limit the text    coderanch.com

Hi Everybody again, I have a problem........ I need to limit the text inputed by the user in the textfield..i mean i set the size of the textfield to say 25 and i need to limit the max char or max int to say 50... How do i do it in JAVA ..... Thanks in advance Kajol

34. Text with AWT & JDK 1.1.8    coderanch.com

35. javax.swing.text.html package    coderanch.com

36. Update the TextFile    coderanch.com

hi!!! Friends, I am updating the Text value for the particular location like coloumn 10 to 18 of that line. First I want to read the text value of column 10-18. Then i will connect to the database through the ODBC (this part I know how to handle). After that, I will get the new value and I will replace that ...

38. Justifying text    coderanch.com

40. Custom Swing Text Component?    coderanch.com

Hi, Maybe someone can help me with this problem. I need a text component in Java that resizes itself dynamically. For example, it starts off at initial size (1 char wide and high), surrounded by a black rectangle. As I type, this rectangle will grow horizontally, and can grow vertically up until 5 lines. Also, this component will be wrapped inside ...

41. Text wrapping    coderanch.com

I posted this question over in the 'Java Intermediate' forum, but thought the nature of my question might be better suited for this forum. Without going into too much background detail, I need to parse a bunch of words separated by spaces, like a long paragraph, into a list (probably an ArrayList.) Each element in the list will be a String ...

42. How to add tags to entering text    coderanch.com

43. Stop text from wrapping    coderanch.com

In a JTextArea, all you have to do is call setLineWrap( false ) on it and stick it in a JScrollPane... For a JTextPane, you have to override two methods... getScrollableTracksViewportWidth() and setSize()... Here's some code that shows how to turn off line wrap in both components... import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TextComparison extends JFrame { JTextArea ta; ...

45. Text width.    coderanch.com

Hello, I have a label whose text is set by setText method with html tags embedded. So some of characters is bold & some plain in the label text. I need to get the font style of each & every character of the label text.It may be bold or plain or some other style. So pl.. help out. with regards, SonaraRahul. ...

46. Underlining text without using HTML    coderanch.com

47. Getting the line-number of a text    coderanch.com

48. text not displaying well    coderanch.com

49. How to limit text length?    coderanch.com

50. Text Alignment Question    coderanch.com

51. Text out of displayed region    coderanch.com

52. Getting text from swiing components    coderanch.com

53. Displaying Text Vertically    coderanch.com

54. Putting variable text over a splash screen    coderanch.com

I am using a splash screen at the start of my program: // Splash Screen ImageIcon image = new ImageIcon("./images/SimTrade_SplashScreen.jpg"); JCSplashScreen splashScreen = new JCSplashScreen(image); splashScreen.setVisible(true); try { Thread.currentThread().sleep(5000); } catch (Exception e) { e.printStackTrace(); } splashScreen.setVisible(false); splashScreen = null; It is simply a small image with the name of the software. I want to include a variable tagline underneath the ...

56. Text question    coderanch.com

57. Text input    coderanch.com

Hi all I want to make use of several input boxes where a user can enter any amount of decimal numbers say from 1 to 50, use that info, shuffle it and display the numbers.I found only TextField class,but it does not give you an option to restrict values entered to two values only. Can someone perhaps help or is there ...

58. problem in text direction    coderanch.com

Hi all of you in any window application when i pressed the Alt+shift keys it's swich between the text direction form R to L or From L to R and my country use the arabic language (RTL). if anyone have a solution tell me please another Question is the any way to set a Label for any component in arabic language ...

60. reverse text    coderanch.com

61. Displaying text in GUI'S.    coderanch.com

You can also call a couple other things too to make it even better - without looking them up (I don't have my code with me) they are something like: setFocusEnabled(false) setSelectionEnabled(false) and there was another to set the cursor in the text area not to show - I forget what call that was. Try selecting text in you rtext area ...

62. Changing Title text    coderanch.com

63. getting the text    coderanch.com

Ben, Just to elaborate a bit on what Don posted, the Java API is your friend. If you look at the API for JTextField you will notice that the method setText() takes a String as an argument. You tried to pass it an int, hence, the compilation error. Also, look closely at compliation errors. They are pretty good, though not always, ...

64. save as text    coderanch.com

65. How do I make a text appear from the right in JTextWindow ?    coderanch.com

I have a little project on my spare time, featuring the developing of a simple and memory-insufficient calculator. In Java, of course. Anyway, as the name of the thread suggests I want the numbers to appear from the right in the textfield of the calculator. The textfield that I use is, as the name of the thread also suggests, a "JTextWindow" ...

66. Formatted text display.    coderanch.com

67. rotate text    coderanch.com

can anyone help me, I am trying to rotate the text for the scale of my x-axis, but when I use the Graphics2D rotate-method, everything disappears... I did it the following way: g2.rotate(45.0d) drawString("200",10,10); g2.rotate(-45.0d) Why don't I see anything? Maybe I have to use other coordinates? I tried many variants, but non worked... Maybe theres another way to rotate a ...

69. starting a new line of text    coderanch.com

import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JTextArea ta = new JTextArea(); StringBuffer numbers = new StringBuffer(); for(int i = 0; i < 100; i++) { numbers.append(i + "\n"); ta.append(String.valueOf(i) + "\n"); // either this, as you go } // ta.setText(numbers.toString()); // or this, at the end JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new ...

70. problem with TEXT    coderanch.com

getGraphics() only returns a Graphics object once the component has physically appeared on the screen. Before then (such as during the constructor), getGraphics() may return null, and so you'll get NullPointerExceptions like you see here. You can (and should) do this work when you override the paintComponent() method; the Graphics argument won't be null.

72. lost text    coderanch.com

Hi there, In my project I save objects to file. One such object I call Listbox. It extends JScrollPane and its viewport contains a JList. It looks like so: public class Listbox extends JScrollPane implements InputTool, Serializable { private JList list = null; private String id = ""; private String[] values = null; private static final String[] EMPTY_ARRAY = new String[0]; ...

73. javax.swing.text package    coderanch.com

Let's say I got over-ambitious and decided to rewrite the text package in swing. So I have my own javax.swing.text package (I know that is not koshur). Is there any way to ensure that when my application is run (executable jar file), it uses my text package instead of the regular text package in rt.jar? Will it use mine by default ...

74. Drilling down to component with text    coderanch.com

75. How to read text file to JScrollPanel?    coderanch.com

Thanks for the welcome Joe and the links. I have read many of those descriptions, but I am just not certain how to go about implementing them. Here is my code thus far. I know I need to install a statement where the System.out.println is currently at. That was just a test to see if things are working good to that ...

77. GUIing a text-based app    coderanch.com

78. Text Alignment    coderanch.com

79. Reading from text file    coderanch.com

Hey there, I hope this is the right place to post this question. I'm new here - so forgive me if I'm posting in the wrong place. Can someone give me some code for reading from a text file and assigning each line to a variable? The text file looks like this: 200000 7.5 30 The text file is located at ...

80. Text on the Desktop    coderanch.com

Hi all, I want to print some text on the desktop. How can I do this? Lets say I have an application that act as a notepad where u can put small notes. I want this note to be displayed on the desktop all the time. I think about doing this by Class MyClass extends JWindow{ ----------------------------------------------------- In side I have ...

81. TableRenderer with multiple lines of text    coderanch.com

You can do the following on the Text Area: theTextArea.getPreferredSize().height That takes into account the space required for the borders. However, I wouldn't recommend that as it would slow down the painting of the table. I would recommend, that you find out how much height each line requires by trial and error. Assuming that 18 pixels is appropriate, then set the ...

82. swing display wrapped text    coderanch.com

I'm simply trying to put a neatly-wrapped, un-editable block of text on a Swing application but I'm not finding a simple solution. I tried a label but I can't figure out how to make the text wrap. I tried a textbox but I get scrollbars and I get line-breaks within the words rather than a neat break. Should I be using ...

83. Text is not saved in file...WHY ??    coderanch.com

84. Paragraphs in a text component - How ?    coderanch.com

Thanks for the help Morgan. That would put a new line in between the two paragraphs but what I want is to not have a newline. I want to have space between the last line of the preceeding paragraph and the first line of the following paragraph, that is larger than the space between the lines within both paragraphs - like ...

85. Styled text?    coderanch.com

86. HTML and disabled text    coderanch.com

you can use the font tag, something like this import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing extends JFrame { public Testing() { setLocation(400,300); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(2,1)); final JButton btn = new JButton("Line 1
Line 2
"); JCheckBox cbx = new JCheckBox("Disable button"); panel.add(btn); panel.add(cbx); getContentPane().add(panel); pack(); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ JOptionPane.showMessageDialog(null,"Hello World");}}); cbx.addActionListener(new ...

87. displaying text files in Jess    coderanch.com

Hi, I was wondering if you could help, i am creating a GUI in Jess with various menu options. On click on one of the options I would like a text file to appear on the interface. Please could someone give me some help on how to do this as i have tried without success. Kind regards, thanks in advance, Grace ...

88. reading text file into GUI    coderanch.com

Hi all, Newbie here...trying to learn it by using it.. My first post here at Java Ranch...looks like a great place! I am using a JFrame with JPanel (with radiobuttons and jtextfields) and am wanting to get data from a text file (around 100 words) and input 4 words at a time into my gui. I have been trying to do ...

89. Style Text pane    coderanch.com

90. MS Access like text import wizard    coderanch.com

Are there any freeware or open source MS Access text import wizard style java components out there? I am building a utility that will allow users to convert flat-file text output from database pulls/reports to database columns. Data columns are visually apparent, but output is variable enough that character seperation filters won't always work. Also there are divider records (divides output ...

91. how to save text as gif ?    coderanch.com

hi, How could i save text i typed into a textArea as a gif. Fisrt: Imagine your typed up a report and saved it as a text file (.txt) or you wrote and saved a java file (.java) Now: Imagine you wanted to open this file? I want to view my file as a thumb gif and scroll into it, as ...

92. save information to a text file    coderanch.com

93. Display text in a JDesktop pane    coderanch.com

94. Formatted text pane problem    coderanch.com

JTextPane pane = new JTextPane() // text String[] wordsArray = new String[] {"Hallo ", "Pane" }; String a = arrayToString(wordsArray); // add to pane pane.setText(a); // format SimpleAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setForeground(attrs, Color.red); StyledDocument sdoc = pane.getStyledDocument(); sdoc.setCharacterAttributes(6, 9, attrs, true); //change text wordsArray[1] = "Welt"; String b = arrayToString(wordsArray); // add to pane pane.setText(b); pane.validate();

96. Hover Text Vs ToolTipText    coderanch.com

Hi, My question is regarding how to decide which one to use HoverText/ToolTipText ? I want to show a statusLine for a View and some detailed information should be displayed after user clicks/hovers on the image on status bar. I tried using tooltiptext and that seems to work fine. However I want to understand how a toolltip can be compared to ...

97. Accessible text in awt program    coderanch.com

This may seem like a strange question about AWT, but I hope someone can help. The details are this : I am trying to gather text from a java program that is already running and its an AWT gui. The components I'm interested in are non-editable labels as far as I can tell. The environment is winxp and the idea is ...

100. retaining text of components    coderanch.com

hello friends, how to retain a component's text, when it called from diffrent classes? if fact, there are many indirect ways to achieve this, but i think, it would be better to use any class or any other method specialy defined to solve this type of problems. any idea would be much appreciated thanks