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

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

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!

StyledText nullpointer

Im working with SWT StyledText to display data to the user in one part of the window. In another part I have a graph, over which I slide my mouse pointer. As I slide my mouse over a point in the graph, it highlights the corresponding entry in the StyledText Area.
I want my textArea to automatically scroll to the newest change, so I am using .setTopIndex().
To determine the index I need to be able to look at which entries in the textArea changed from not highlighted to highligted, I use the following (to check if my styleRange changed):
styledText.getStyleRangeAtOffset(offset)
So far my program functions correctly. My next check is:
styledText.getStyleRangeAtOffset(offset).isUnstyled
or
styledText.getStyleRangeAtOffset(offset).foreground
or something like that. Here enters the problem. When I call any of these I get a nullPointerException.
Thank you for all the pointers :) after some debugging I discovered that the unedited styleRange is null. That explains the nullPointer I kept on receiving

java multiline button - disable color-issue

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.

Formatting JEditorPane's cursor, tooltips, links

Right now, I'm using Java Swing to create a JEditorPane primarily for its ability to have hyperlinks. I've successfully been able to display links and have them execute behavior upon a click, but I'm running into a few problems with formatting.
How can I set the cursor so that it normally is an arrow, but changes to a text cursor when hovering over text? (In essence, the behavior a cursor has within a web browser). I tried
EditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR))
but that made it a text cursor everywhere, even when not hovering over text. Right now, hovering over a link shows a pointer hand; I'd like to maintain that functionality as well.
What is the best way to show tooltips or mouseover text when hovering over a link? I tried modifying the title attribute of the link but nothing showed up.
I was trying to implement links to skip down to a subsection of the page, much like http://en.wikipedia.org/wiki/Xkcd#History would take you directly to the History subsection of Wikipedia's xkcd page. How can I do this?
An answer to any of these would be great (and multiple would be awesome xP). Thanks a lot for your help!
As you said one can simply give answers to a single point as well, let me try one by one, here is the answer for your last Point 3
Just provide an id to your tag like this
<h1><a id = "top"></a>First Line</h1>
Now somewhere in the bottom of your page write this :
<p>Return to TOP</p>
Clicking this link, you will reach the above area of the PAGE.
Points 1 & 2 may be addressed using the approach mentioned here. In particular, the view/model conversion methods will let you condition setCursor() and getToolTipText(), respectively.
You can get source from here http://java-sl.com/JEditorPaneStructureTool.html
It shows how to obtain text view bounds. First you get caret position for current mouse poiunter using viewToModel() method. Then go down the Views tree achieving leaf view and calcualte it's bounds. See this http://java-sl.com/tip_view_rectangle.html
If your mouse pointer in the view's rectangle then your mouse over text.
You can check whether the text in caret position is link and show your tooltip.
Use this http://java-sl.com/tip_links_in_editable.html to see how to detect whether mouse is over link.
Point 3.rd is answered by #nIcE cOw

How can I create an AutoComplete popup in a JTextPane in Java?

I am creating a SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for table name etc. like Eclipse.
I think the appropriate class for displaying info on top of another component is JPopupMenu, which already handles layering correctly to display itself. JPopupMenu has a show() method that takes its 'parent' component as an argument, and it will show itself in that component's coordinate space. Since you want to display a selection of terms for the user to choose from, a menu seems appropriate.
To check for text changes, you'd add a DocumentListener to the document that's wrapped by the JTextPane; you can access it using getDocument().
To find out where the cursor (actually, the caret) is, you can use getCaretPosition(). That returns the caret's position within the text stream as an int. You can use modelToView() to translate that position to actual (x,y) coordinates. That in turn will tell you where to show your menu.
You can use addKeyListener() to catch keyboard events on your JTextPane, like hitting Ctrl-Space.
The combination of all that should allow you to do what you're looking to do.
You can also use http://fifesoft.com/autocomplete/. You can install it on any JTextComponent.
For things like this you probably should consider layered panes so your auto-complete suggestions appear in the correct place and z-order.
Furthermore you will have to look for changes in the JTextPane to know when the user is typing and you will need a parser that understands what is typed so you can offer the feature only at appropriate points.
It's not quite clear what exactly your problem is and what you got so far.
I achieved this by adding a key listener to the JTextPane and checking for CTRL + Space keystrokes. When the appropriate key combo was detected the listener went off and looked up the list of possible matches based on the characters directly to the left of the cursor at the time of the key press and found the best matches and displayed them to the user in a JPopup. If there was an exact match then it simply replaced the partial text with the match. If no matches were found an option was given to the user to add the text that they had already typed, edit it and record it into the list of acceptable data.
We use jide. They have a lot of components that help you do this kind of thing really easily

Categories

Resources