user2407152
user2407152

Reputation: 49

How to create bold print in TextArea?

I've research and seen many versions of this

JEditorPane textarea = new JEditorPane("text/html", "");
listArea.setText("<b>Bold</b>");

Unfortunately that does not seem to work for me, I'm not sure if it can be a result of different versions of netbeans as I am new to working with it.

How to I bold certain words?

EDIT: Well there is not much to show...it is quite literally a line after a actionPerformed Button...

private void sortButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           

        JEditorPane listArea = new JEditorPane("text/html", "");
        listArea.setText("<B>Adjectives</B>" + "/n"); //I've tried both upper and lower case

Upvotes: 0

Views: 2738

Answers (2)

Pshemo
Pshemo

Reputation: 124275

Is it possible that root of your problem is that you have declared textarea but changing text in listArea?

Could you try this code to test it?

JFrame frame=new JFrame();
JEditorPane textarea = new JEditorPane("text/html", "");
//listArea.setText("<b>Bold</b>");
textarea.setText("<b>Bold</b> and normal text");
frame.add(textarea);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

Upvotes: 2

camickr
camickr

Reputation: 324207

Read the Swing tutorial on Using Text Components for working examples.

If you still have a problem the post a proper SSCCE demonstrating the problem.

Upvotes: 2

Related Questions