Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Tekst polja u javi

[es] :: Java :: Tekst polja u javi

[ Pregleda: 2981 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

kernel82

Član broj: 36093
Poruke: 58
*.teleportgroup.net.



Profil

icon Tekst polja u javi24.02.2005. u 14:53 - pre 233 meseci
Da li je moguce u javi napisati rtf fajl odnosno, da mogu svakoj reci da dodelim drugu boju?!
Walk on, walk on
with hope in your hearts
And you'll never walk alone
You'll never walk alone.
 
Odgovor na temu

dacho
Montreal

Član broj: 4096
Poruke: 38
*.dialup.sprint-canada.net.



Profil

icon Re: Tekst polja u javi24.02.2005. u 23:23 - pre 233 meseci
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());
    }
 
Odgovor na temu

[es] :: Java :: Tekst polja u javi

[ Pregleda: 2981 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.