question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Placeholder in TextArea

See original GitHub issue

Hey,

I was wondering whether it was a conscious decision to not offer a placeholder for JTextArea. I’ve seen you are using the default logic from Java via reflection to draw a clipped String. I am assuming you didn’t implement this because it would require reimplementing the drawing and clipping a bit? Would you be accepting this as a PR if I was to try it with line wrapping AND clipping?

Alternatively a non wrapping version might already be better than nothing.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DevCharlycommented, Oct 13, 2021

I was wondering whether it was a conscious decision to not offer a placeholder for JTextArea.

no, simply did not need it… 😉

I’ve seen you are using the default logic from Java via reflection to draw a clipped String. I am assuming you didn’t implement this because it would require reimplementing the drawing and clipping a bit?

yes, why reinvent/reimplement something that the JRE provides.

Would you be accepting this as a PR if I was to try it with line wrapping AND clipping?

Sure.

There is already some code in FlatLaf that splits a string and paints multiple lines:

https://github.com/JFormDesigner/FlatLaf/blob/d10bcfc72fda6156ab104e1c52835eeef4282b2c/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolTipUI.java#L121-L132

Maybe extract this to new method FlatUIUtils.drawMultiLineString( JComponent c, Graphics g, String text, int x, int y, int width, boolean clipLines ) and use it for TextArea placeholder too ?

0reactions
DevCharlycommented, Nov 8, 2021

Do you want a new property or reuse JTextField.placeholderText?

Reuse JTextField.placeholderText.

… without copying it’s code or manipulating it’s properties …

Since the license of OpenJDK is GPL, it is not allowed to copy code from OpenJDK to FlatLaf (Apache license).

You could create a second JTextArea and use that for rendering the placeholder text…

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML textarea placeholder Attribute - W3Schools
The placeholder attribute specifies a short hint that describes the expected value of a text area. The short hint is displayed in the...
Read more >
HTML | <textarea> placeholder Attribute - GeeksforGeeks
The <textarea> placeholder attribute in HTML is used to specify the expected value to be displayed before user input in textarea element.
Read more >
HTML placeholder Attribute - Tutorialspoint
HTML placeholder Attribute - The placeholder attribute of the <textarea> element is used to set a placeholder text in the textarea. A placeholder...
Read more >
HTML5 textarea placeholder not appearing - Stack Overflow
I cannot figure out what is wrong with my markup, but the placeholder for the text area will not appear.
Read more >
HTML textarea placeholder Attribute - Dofactory
The placeholder attribute adds a hint to a <textarea> element. The hint appears as muted text inside the control and specifies what data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found