[ kernel82 @ 24.02.2005. 14:53 ] @
Da li je moguce u javi napisati rtf fajl odnosno, da mogu svakoj reci da dodelim drugu boju?! |
[ kernel82 @ 24.02.2005. 14:53 ] @
[ dacho @ 24.02.2005. 23:23 ] @
Nadam se da sam shvatio pitanje, ti hoces da imas novi JFrame i u njemu text field gdje je svaka rijec napisana drugom bojom. Ako to hoces da uradis, moraces upotrijebiti jedan od Java Styled Text Area komponenata (npr. JTextPane). JTextArea nece raditi jer kad u njemu promjenis boju promjenice ti se boja cijelog teksta. Ispod imas prijmer kako da ovo uradis sa JTextPane. Svaki put kad dodajes text u StyledDocument, moras mu dodati novi stil (npr. promjeniti boju).
Code: public void addToSentMessageHistory(String sentMessage) { StyledDocument doc = (StyledDocument)clientMessageHistoryArea.getDocument(); try { // Create a style object and then set the style attributes Style style = doc.addStyle("StyleName", null); // Font size StyleConstants.setFontSize(style, 15); // Set text style preferences // Italic StyleConstants.setItalic(style, true); if(count % 2 == 0) // Bold StyleConstants.setBold(style, true); // Font family StyleConstants.setFontFamily(style, "SansSerif"); // Background color StyleConstants.setBackground(style, Color.yellow); // Foreground color StyleConstants.setForeground(style, Color.white); doc.insertString(doc.getLength(), sentMessage, style); } catch(BadLocationException e) { System.out.println("ClientFrame addToReceivedMessageHistory() exception: " + e.getMessage()); } clientMessageHistoryArea.setCaretPosition(clientMessageHistoryArea.getDocument().getLength()); } Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|