Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:01:21+00:00 2026-06-09T21:01:21+00:00

I have a JOptionPane: JOptionPane.showMessageDialog(null, text); The text is a sting: String text =

  • 0

I have a JOptionPane:

JOptionPane.showMessageDialog(null, text);

The text is a sting:

String text = "Hello world."

What I want to do is change the color of the text, specifically a single word, lets say ‘Hello’. SO what I’ve tried is:

String t1 = "Hello";
String t2 = "world."
Font serifFont = new Font("Serif", Font.BOLD, 12);
AttributedString as = new AttributedString(t1);
as.addAttribute(TextAttribute.FONT, serifFont); 
as.addAttribute(TextAttribute.FOREGROUND, Color.red);


JOptionPane.showMessageDialog(null, as+t2);

I’m not familiar with attributedtext() and this wont work. It does this:

“java.text.AttributedString@479c479cworld”

Is there a step I’m missing? Is this not the right way? Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:01:23+00:00Added an answer on June 9, 2026 at 9:01 pm

    It should be possible to use html to solve this, ie

    String t = "<html><font color=#ffffdd>Hello</font> world!";
    

    See http://docs.oracle.com/javase/tutorial/uiswing/components/html.html for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: String message = <html><a href=http://www.videolan.org/vlc/>http://www.videolan.org/vlc/</a></html> JOptionPane.showMessageDialog(null, message, Error, JOptionPane.ERROR_MESSAGE, new
Hi i have something like this JOptionPane.showMessageDialog(null, Config.CHECK_INTERNET_CONNECTION); System.out.println(go); // HERE I CHECK MY
I have a dialog box that is: JOptionPane.showMessageDialog(null,Once medicine is given, measure temperature within
I have a question about joptionpane. Using JOptionPane.showMessageDialog(...), we can create a message dialog.
I have an image inside the JOptionPane and I want it to disappear whenever
import javax.swing.*; public class MainP2 { public MainP2() { JOptionPane.showMessageDialog( null, Hi welcome to
I have a weird behavior with the JOptionPane.showInputDialog(...) method (and other methods of JJOptionPane).
Following situation: I have a JFrame and call JOptionPane.showInputDialog(test) . The modal dialog will
I have a Java application and I want to use SQL database. I have
I have the following code : /* * To change this template, choose Tools

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.