scrolling text in a bar - java

I'm making a program in java that recive some strings and then display them in a new frame scolling them in one line, like the news, (shown below)
There, the text are displayed in a line, like what I need, but my problem is that I don't know what I should use in java, I though about put a panel on a frame and then a textfield inside the panel, then I realize that it's impossible because for every message I may need to change the color of background for an highlight message...
So, if anyone can help me, can you tell me what should i use for the diferent message and how i can get the text scrolling?
Thank you all in advance!

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

My EULA is not displaying

Hey there,
So I have the EULA code written up and in the application, I have the strings set the way it says to, i have it calling it in the main pages onCreate, and I have a EULA.txt written up and in the assets section. The problem is that it does not display the text. The box shows up with the title, a section where the text should be displayed, and the accept/decline buttons. I'm not exactly sure why the text wont display in it. Would appreciate any help... thanks.

Refreshing the Contents of a Box after changing the contents

I have a java Box in which are various components. When the user performs an action, I want to empty the box, put a different set of components in it and then represent the box to the user. The box is part of a JDialog box. I am able to empty the box and repopulate it, but the display does not reflect the new contents. It is simply a blank display (I assume reflecting the fact that I emptied the contents of the box). I repaint the box after I put the new contents in but the display is blank in the area where the box is. Oddly enough, if I first add a line border to the box, then repaint it, the contents of the Box appear on the screen. This is most bizarre behavior. Any ideas why this is happening and how to get around this problem?
Thanks,
Elliott
Are you adding and removing the contents from the EDT? if this is occuring on the wrong thread weird repaint behavior can result.
Also might want to try
dialog.revalidate()
if the above is not the issue instead of calling repaint

Swing: Programmatically select a text

I have a very simple Swing GUI with just a JTetxtArea. I am trying to programmatically select a part of text using:
textArea.select(startSelection,endSelection);
This work. However as soon as I add some other components to the GUI I do not see selection anymore
frame.getContentPane().add(button);
frame.getContentPane().add(textArea);
textArea.select(startSelection,endSelection);
I suspect that during layouting the gui, some event causes the text to be deselected. Am I right? And could anybody suggest a solution?
My goal is to have a program which displays a text, and allows the user to input start and end selection position, and a selection appears between these two position. Thank you.
Text selection only shows when the text component has focus.
Text components also support "highlighting" by using the getHighlighter().addHighlight() method. In this case the highlighting remains whether the component has focus or not.
If you need more help post your SSCCE that demonstrates the problem.
If what you really want is just a selection, not highlight (which behaves differently), you can use JTextComponent.getCaret().setSelectionVisible(true).

Categories

Resources