• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Bold and Underline User Input

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing some code for a class project.  I have main parts done, but I am just trying to add the extras that the professor has eluded to.  How would I bold and underline the text as they enter it?

IE:   Enter number of boxes: 3
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would require a component that allows a user to enter data and that supported some kind of markup the code could wrap around the user's input.
I don't currently know of a component that does that.  Maybe someone with better Swing/JavaFX knowledge will come along.
Maybe the JEditorPane class would be of use.
 
Trey Burkhalter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the following to ask for the number:

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is input a Scanner object reading from System.in?

I don't think its easy or even possible to control what the OS does to display text that is entered on a console.
And it is not part of java.
 
Trey Burkhalter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes sorry.  I made certain assumptions and I really need to stop that lol

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:. . . I don't currently know of a component that does that.  . . .

As far as I remember, you can put basic HTML tags onto a JLabel. There are ways to get a terminal to show bold or underlined text, but that is complicated and I can't remember how to do it, and it is platform‑specific.
Remove the keywords public and static from the code you showed. The error message might go on about non‑static and it makes people think the answer is to mark something static. But the correct solution is to remove the code using it from a static context.

And welcome to the Ranch
 
reply
    Bookmark Topic Watch Topic
  • New Topic