< prev index next >

src/java.desktop/share/classes/java/awt/TextField.java

Print this page

        

*** 196,206 **** * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true. * @see java.awt.GraphicsEnvironment#isHeadless */ public TextField(String text, int columns) throws HeadlessException { ! super(text); this.columns = (columns >= 0) ? columns : 0; } /** * Construct a name for this component. Called by getName() when the --- 196,206 ---- * @exception HeadlessException if GraphicsEnvironment.isHeadless() * returns true. * @see java.awt.GraphicsEnvironment#isHeadless */ public TextField(String text, int columns) throws HeadlessException { ! super(replaceEOL(text)); this.columns = (columns >= 0) ? columns : 0; } /** * Construct a name for this component. Called by getName() when the
*** 295,311 **** * text component to be the specified text. * @param t the new text. * @see java.awt.TextComponent#getText */ public void setText(String t) { ! super.setText(t); // This could change the preferred size of the Component. invalidateIfValid(); } /** * Indicates whether or not this text field has a * character set for echoing. * <p> * An echo character is useful for text fields where * user input should not be echoed to the screen, as in --- 295,327 ---- * text component to be the specified text. * @param t the new text. * @see java.awt.TextComponent#getText */ public void setText(String t) { ! super.setText(replaceEOL(t)); // This could change the preferred size of the Component. invalidateIfValid(); } /** + * Replaces EOL characters from the text variable with a space character. + * @param text the new text. + * @return Returns text after replacing EOL characters. + */ + private static String replaceEOL(String text) { + String[] strEOLs = {System.lineSeparator(), "\n"}; + for (String eol : strEOLs) { + if (text.contains(eol)) { + text = text.replace(eol, " "); + } + } + return text; + } + + + /** * Indicates whether or not this text field has a * character set for echoing. * <p> * An echo character is useful for text fields where * user input should not be echoed to the screen, as in
*** 702,711 **** --- 718,728 ---- private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException { // HeadlessException will be thrown by TextComponent's readObject s.defaultReadObject(); + text = replaceEOL(text); // Make sure the state we just read in for columns has legal values if (columns < 0) { columns = 0; }
< prev index next >