java multiline button - disable color-issue - java

i have the following problem:
i want a JButton with a line break. i am using the html method to get it done.
<hmlt>Bla<br>Bla</html>
the problem appears if i disable the button. it works fine except on the "html-styled" button. the color from the button stays the same.
on an other button i am just using &#8592+;(without the "+") and it works fine, the arrow gets grayed out if i disable him.
so i searched some time for the unicode or html number for the line break, but it didnĀ“t work(for example &#10+;)
so can anybody give me an advice? i know it could be done in java, but i prefer the html way, cause it is faster to implement :)

See How to Use HTML in Swing Components: ButtonHtmlDemo:
..Note also that when a button is disabled, its HTML text unfortunately remains black, instead of becoming gray. (Refer to bug #4783068 to see if this situation changes.)

I don't think components with HTML text will be affected by the modified text style that disabling them usually causes.
You could override the button's getText() method to return a different HTML including styling for the text depending on whether the button is disabled or not, but if you want to get it just right it would probably be easier to extend the UI to allow multiple lines without relying on HTML.

Related

Hovering Dialogue Box

I am creating a log in form in Java. I have already completed the entire structure of the program, as well, I have designed it's purpose and perfected it's functionality. However, now I am focusing on styling the program. I'm proud of it as it is and it's fine if I don't add this feature, however I really would like to and cannot discover how.
In summary, when a username is typed into the login form, I have a void that runs after the JTextField loses focus. This void searches for possible invalid characters such as spaces. I can successfully change the color of the border on my JTextField, and other attributes I wish to change, however I also would like to have a small dialogue box to hover over the JTextField to say what specifically is wrong with what was typed. (e.g. "Your username cannot contain spaces!").
Ideally, it would be a rectangle that could simply be filled with text, and only appear when the username is deemed incorrect, and be able to disappear when it is fixed ( I can handle the appearance and disappearance most likely, I just need help with creating this box thing ).
Is there any such thing as like a "JHoverBox" or something that I could add to my JTextField?
Well, you can have, as Gene said, a label that's normally empty near the text field, but you can have it coloured like the background colour. This will make the user not able to see it, and when you detect something wrong, you can change the colour and add the text. Simple!

How to prevent text from turning to ellipsis on small buttons in JavaFX?

If I make button relatively small, it's caption turns to ellipsis.
How to turn off this feature?
Don't let the button go below it's preferred size, then it will never need to elide the text of the button label:
button.setMinSize(Button.USE_PREF_SIZE, Button.USE_PREF_SIZE);
I want to make very small button
You can use any of the below either separately or in combination:
Apply CSS to use a very small font in the button.
Make the label text for the button very short.
Use brian's answer which proposes explicitly setting the ellipse string to empty.
Use a small graphic icon instead of text.
You can use setMinSize as documented above in all cases (if you wish the button not to go below a preferred size truncating or eliding content).
In all cases, if you wish, you can also apply CSS to minimize the padding between the label and button the border.
From your previous comment (I want to use simple captions like "<" and ">"), I think option 2 (Make the label text for the button very short) is what you want.
You may also be interested in Joel's Designing for People Who Have Better Things To Do With Their Lives which would indicate, usability-wise that very small buttons are usually a pretty bad idea.
in your label/button you can use the textOverrun property to turn off ellipsis.
textOverrun.set(OverrunStyle.CLIP);
this is probably a bit late for you, so i am putting it here for lone wanderers digging up this question.
It puts ... because there's no room for the text. You can use bigger buttons or a smaller font but if you really want the dots gone use button.setEllipsisString(""); , but then you just get truncated text.

Input Text fields don't move cursor on mouse click?

I have an issue with all of my Input Text fields, maybe someone has an idea:
I'm using GWT, and just discovered that the text in of my Input Fields cannot be selected using Mouse. Also clicking inside the text does not move the cursor.
But giving them Focus using the cursor works. Selecting all with CTRL+A as well as moving the cursor with Arrow Keys works as expected.
I inspected the TextBox specific onBrowserEvents() method and can see, that click events are received well. Just somehow they don't modify the text input control in the browser.
I tested different machines and different browsers, which all behave the same. So it must be something in my Application.
Maybe somebody has an idea what I could have done wrong? I can't even imagine anything that could produce this behaviour on all of my input fields.
It just turned out to be a CSS issue:
I had -moz-user-select: -moz-none; to prevent doubleclick issues for some of my components. I now excluded the input element from it and everything works fine again.
I use this to solve the problem with selecting text and moving the cursor on the text in the inputs:
*, ::before, ::after
-webkit-user-select: text

Ext Gwt setVisible results in disappearing fields

I'm having an issue where I have 4 form fields in a fieldset. If certain conditions are met, I use setVisible(true/false) to hide or show the fieldset.
I'm running into a problem where I originally hide a fieldset, but when I make it appear, it doesn't display the labels and textfield boxes.
If I do it in reverse, where I show the fieldset, then hide it later, I have no problem switching between the views and having it show up properly.
I use an HBoxLayout for the fieldset. I'm wondering if it's the layout that could potentially be causing the problem or maybe it's the rendering order?
Does anyone have a workaround or solution?
Thanks.
The workaround I found was removing and adding the fields again. It's still not identical, the fields seem to be pushed over a bit from the left side, but it at least shows up again.

Looking for an efficient Java Swing based console

I'm looking for a highly efficient Swing Java component which I can just plug into my application UI. I already tried using the classes within Swing such as JTextArea with no avail; they simply aren't high-performance enough and have any crippling drawbacks. Additionally, it'd be nice if it had standard console features such as scroll-lock, clear console, colours, and so on.
Edit: Forgot to say, this console will have a lot of debug information streaming into it, and it needs to be fully scrollable.
Cheers,
Chris
I fail to see what is wrong with using a JTextPane. It supports attributes which you can specify as each piece of text is added to the console. Clearing it is also obviously a no brainer. When added to a scroll pane it also supports scrolling.
You can add scroll locking by using Smart Scrolling.
Plus, it removes text too early and
No idea what that means as text is never removed unless you specifically remove it from the document.
doesn't allow the user to scroll while
input is being entered (afaik). The
effect is that you just see text
flashing while the number of rows
remains the same.
By default the text scrolls automatically as text is append to the document assuming the code is executed on the EDT. This scrolling can be controlled the the example provided in the link above.
Edit:
but I'd still like a library solution
I don't know of any
auto-colourise text coming from
different streams
The Message Console might give you some ideas.
(i.e., detect [error] prefix on a
line) and colourise lines based on
this)
This is easily done by adding a DocumentFilter to the Document of the text pane. You can add attributes as text is inserted into the Document.
Be sure that you read about the Event Dispatching Thread (EDT) in swing!
BTW: a simple search 'java swing console' will give you a lots of hints OR you could use/adapt the beanshell textfield which is a jtextfield too ...

Categories

Resources