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
Related
I´m building a simple word-editor in java. Currently, everything´s working fine. Now I want to create "Pages", like in word. The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it. With a scrollbar I would be able to scroll between them. So far this wouldn't be problematic. However, all the pages should belong to a single document, and if I were to delete a line on let´s say page 2, every line on every other page will be moved up. (For example) Is there an easy way to do this, or will I have to create DocumentListeners for each JTextPane, changing everything on each change? Also, is there a way to extend selections over multiple pages?
Personally I havn't tried anything as of yet, since I want some tips before writing myself into a corner. I thought that I could make the pages uneditable, and instead use a caretListener to check the position the user clicks on, to edit an invisible infinite JTextPane containing the actual document, which would write it´s content to the visible pages.
Lots of unknowns, but maybe the following will give you something to think about.
all the pages should belong to a single document,
Agreed.
The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it
Maybe add each text pane to a JScrollPane, but don't display the scrollbars or Border of the scroll pane.
if I were to delete a line on let´s say page 2, every line on every other page will be moved up
You would need to manually control the viewport of each scroll pane. The first page would position the viewport at offset 0. The next page would position the viewport at the offset that represents your page height.
Then any changes to the Document should be automatically reflected in all the text panes.
You would also probably need to use setAutoScrolls(false) to prevent the viewport from scrolling as you drag the mouse.
is there a way to extend selections over multiple pages?
Selection is a property of the text pane, not the Document.
Not sure what will happen as you try to drag the mouse from one text pane to another.
I'm guessing you might need some special logic. Maybe using mouseEntered/Exited events to trigger this type of processing.
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!
So I am creating a GUI and it has a JTable that is set inside of a JScrollpane. When the user opens the window it displays everything how I want it to. The user can add rows to the table to fill in data and then they can scroll through the information. I also have a JButton which I have set to print the whole window. Now my problem is the table prints but only shows the data in the viewing area. What i was thinking was if the user could drag the bottom corner of the JTable to re size it to show everything then everything would be ok, I'm just not sure if that's even possible or how to do it. Ive been searching and i haven't seem to come across anything like this yet.
Edit:
So for anyone else here is the link to the class I found. It allows you to use the mouse to resize any component.
http://tips4java.wordpress.com/2009/09/13/resizing-components/
To get an image of the entire table you can try using Screen Image, which allows you to take an image of a specific component.
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!
I have a JList inside a Scrollpane. If you click on the list and move the arrow keys up and down it works like you expect, you can move your selection index and display around just fine.
Now, what I want to do is basically have a text box and i'm typing in the text box like "comic" and want it to seek to the index of that value. This WORKS just fine.
Where the problem is when the value of the list box is below, or above the viewable area. When it is, the selected index seeks, but does not change the position of the scrollable region. However, if I press the up or down arrows and requestFocus() to the list, and move up and down it seeks to the right viewable area.
What am I missing to make this happen WITHOUT changing focus. I want to be able to just type in the list all I want and have it show me what is selected. I feel i'm missing something obvious here.
If I understand the question then you should be able to use:
list.setSelectedIndex(...);
list.ensureIndexIsVisible(...);
If that doesn't help then post your SSCCE demonstrating the problem.