JTextField becomes noneditable - java

This is weird - maybe it has a really simple solution, but I have spent two days on it so far! I have a JList in a scroll pane that I want to tab up and down in (and/or use up and down arrows).
I want to position the cursor at the first entry, and colour it, when the JList is displayed. The only way I've found to do this is to select the first entry, then request focus for the JList from inside the cell renderer - in the code that colours the selected row.
This works, but it changes the JTextField immediately below the scroll pane to non-editable. Remove the request focus from the cell renderer code, and the JTextField becomes editable again - but then I have to click on the JList to use the arrows on it or tab through it. Of course, I may be using totally the wrong tools. Help would be much appreciated...
I have just read that only one component can be focusable at a time - but why won't setFocusable() + requestFocusInWindow() change the focus to where I need it? I assume this is why the JTextField is not editable, even though it was set using setEditable(true)...? Are there other requirements that have to be in place before you can make a field focusable/editable?

Related

Need to "link" table cell editor with its table

I need to customise the selection behaviour of the cells inside a JTable descendant. I have a custom cell editor using a JTextField descendant as the editorComponent; there's a focus listener registered on it which manages the desired selection behaviour.
I need different behaviour when tabbing around the table than when another window or application comes to the front and then goes away again.
This is currently not possible, because the cell editor's editorComponent seems to have no off-the-shelf way of knowing (or telling it) that it's the editor for a table cell, so it doesn't know that it's "inside" the table, so my focusGained() and focusLost() think focus is moving between different windows even if I'm just tabbing around in the table.
SwingUtilities.windowForComponent() returns null for the editorComponent.
Before I roll my own solution, is there an accepted way of dealing with this issue? I can't be the first person to need to do this...

How would a dev make a JTable LOOK editable

I'm writing an application that has a JTable, and an edit button that sets the current selected row to be editable. Then once the user is done altering the data, they can click the edit button again (with text that now says "Save") to save the data.
The problem is though, when I set a row to be editable, there isn't a visible difference. I could add some code to the renderer to draw the editable cells a little differently, but I don't know what the proper way to make a cell look editable is. Change the color? Make it look like a JTextField? What's the standard method?
Thanks!
Really this is a user interface design question, not a programming one.
To do what you want you need to supply an appropriate cell renderer with the changes you desire but you will need to decide on your own settings. One option might just be to look at the difference between an editable and non-editable text area and apply those to all the cells on the table. This may be as simple as setting the renderers to disabled for any read-only rows.

Printing a JPanel with a JTable and JTextField

I want to print a Jpanel with two things in it.
I have a Jtable that could have as many as 500 row in it, and I need to be able to print all of them.
I have a JTextfield under the JTable in the JPanel.
I want to print both of these at the same time. The problem I am having is when I print the jtable it only prints the visible part. What I really care about is the content of the JTable and not the Table itself.
Edit: I use Netbeans to build my Gui so I don't really know how to display the code for the Panel, Table, and TextFields.
Here is a picture of the frame everything is in:
The table can have more rows than you can see at once. All the items here except for the button are in a Jpanel, so I need to print this jpanel. What I have found and tried doesn't print all of the jtable, just what is visible to the user.
When you call table.print() it will offer a dialog and you click print. I can't help you more until you post some code but this works for me.

Active Elements in swing JTree, JTable or JList

I need a Container with similar JPanels lined up one below the other which can be selected. I could:
Use a JList with a custom renderer but those JPanels would be passive elements, that's not what I want.
Implement my own Container with 'active' JPanels but those would not be selectable. Or could they made selectable?
Maybe a MouseListener and access to the system default selected-background-colors could be a way but it seems a bit too much effort
Use a JTable or JTree with custom cell editors rendering the 'active' JPanel. But these active parts would only react at the 'second' click, first to activate the editor, second to perform the real action of the JPanel. this is also not acceptable.
To get a more visual impression, here is an example of what this could mean:
A JList containing list items which have each two functional JButtons.
As you've discovered, simply putting a JPanel inside a JList doesn't quite work as you'd like. The JPanel will be passive and won't receive events - essentially all that is happening is your JPanel is simply being drawn, it's not a living component.
Instead of using a JList to put your panels in a list, use a list-like layout manager, such as BoxLayout or GridLayout. If you want all your panels to be the same size, use GridLayout with only a single column.
How to Use GridLayout
How to use BoxLayout
I'm not sure I understand your "example". If you want two functional buttons, then use a JTable where the functional buttons are contained is separate columns. Then your data would be displayed in other columns.
Table Button Column shows how you can do this.
your question(s) isn't clear for me, maybe here
there is JTable, with one TableColumn but without TableHeader, contains JPanel with active JComponents inside (you can implements TableCellEditor for all JComponents) as JComboBox, JButton and JTextField

jList in Scrollpane, seeking and displaying value of selectedIndex

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.

Categories

Resources