Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Add shadow for text in JTextArea

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Add shadow for text in JTextArea

    So, i use JTextArea in my program to show multiline text with custom font, is it possible/and easy to add a shadow to text in JTextArea ?
    And second question, maybe it's possible to use css styles in java on the jtextarea and make shadow with css style ?
    All i need is a component to show multiline text with custom font/size and shadow support, what should i use ?
    As for now, i use this configuration :

    JTextArea textFieldNews = new JTextArea();
    textFieldNews.setOpaque(false);
    textFieldNews.setFocusable(false);
    textFieldNews.setForeground(Color.white);
    textFieldNews.setFont(Font.createFont(Font.TRUETYPE_FONT, new File("fonts/myfont.ttf")).deriveFont(Font.TRUETYPE_FONT, 18));
    textFieldNews.setText("Shocking news, are you shocked ?");


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 601 Times in 516 Posts

    Default Re: Add shadow for text in JTextArea

    You've mentioned a couple different approaches. What happened when you tried each?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Add shadow for text in JTextArea

    Well, i dont know where to start, i only googled for these things, but i found very little info about shadows and other things on text in java, so it's still not clear, if:
    1) java fully supports css styles for swing components;
    1.1) how to open/use css style file in java;
    2) found, that making shadows for text in text fields includes Graphics, if not using css, but no examples or how to guide.

    oracle's examples and tutorials are useless and very bad about everything, but i havent found a site about configuring text in java in general...

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 601 Times in 516 Posts

    Default Re: Add shadow for text in JTextArea

    Googling "java swing text shadow" returns several results. Have you tried any of those approaches?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Add shadow for text in JTextArea

    Yeah, i tried, but it's still unclear :
    1) If i use Graphics/2D, then i convert String into Graphics, there is no usage of real text fields/areas, just converting text into graphics and working with it, then converting it to picture and creating jlabel from that picture :
    1.1) how about new lines "\n" and other logical symbols ?
    1.2) how to align text ?
    2) how to create my own font Font object from file ? there is no constructor Font(File file, ..., ...);
    3) still nothing about on how to use css styles on text in swing.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 601 Times in 516 Posts

    Default Re: Add shadow for text in JTextArea

    You can't use css outright in Swing. There are several libraries available though. Again, google is your friend.

    You've posted a bunch of questions, and the answer is to take them one at a time and create small example programs to try out each problem.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member
    Join Date
    Aug 2013
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Add shadow for text in JTextArea

    I'm trying, but results are not good. In this case google is more of an enemy, because there is no good articles about it, just a few about one or another thing, but no one is about all things together.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Add shadow for text in JTextArea

    I believe the text-shadow property is not supported in Swing (Swing support for many css elements is lacking). Maybe not the best way to go about it, but quickly and off the top of my head: get the Highlighter of the JTextArea and add a new Highlighter, passing your a custom implementation of the Highlighter.HighlightPainter interface. Within the custom implementation you draw the shadow text in the appropriate color.

Similar Threads

  1. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Swing Tutorials
    Replies: 11
    Last Post: October 15th, 2013, 10:22 PM
  2. read text from a JTextArea
    By eiboog in forum AWT / Java Swing
    Replies: 1
    Last Post: November 6th, 2011, 09:37 AM
  3. How To: Add line numbers to your JTextArea
    By Freaky Chris in forum Java Code Snippets and Tutorials
    Replies: 10
    Last Post: March 31st, 2011, 05:18 AM
  4. Replies: 1
    Last Post: May 21st, 2009, 03:41 AM
  5. Java Program to add scroll bars to JTextArea using JScrollPane
    By Flash in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: May 21st, 2009, 03:41 AM