Hai
I am developing a standalone application using Java in which I am using a JTable.The problem is when I enter a multiline text,the entire text is not displayed in the cell while I am typing.I get a scroll when I type a multiline text.How can I get my whole text to be visible while I type.i.e How can I increase my Cell width in JTable while I am Typing. But the entire text will displayed only when I click out of that Cell.Can someone help me how to solve this problem
Thank You Chaithu
You should try a custom TableCellRenderer with JTextArea for example. For typing you'll probably need similar TableCellEditor.
An example can be seen at Java Specialists' Newsletter : Multi-line cells in JTable in JDK 1.4+.
Related
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.
I'm trying to imitate some Excel spreadsheet functionality on my JTable, specifically what I've been calling cell spillover or cell overflow. This occurs when you fill a cell with text with a wider width than the cell is set to. If there is no text in the cell to its right, the words simply keep going into the next cell and beyond.
I feel like this would be accomplished somehow with TableCellRenderer, but I do not know how.
Any help would be much appreciated
I dont know because you did not give alot of detail but a simple use case would be:
When text is entered check for the amount of characters
Check for the width of the cell and look if the text fits
If the text doesnt fit check if the cell next to this one has text
If it has no text, resize the cell to fit the text and make the one next to it smaller.
Or something like that.
But i dont know if JTable allows resizing of individual cells, you should check the JTable API.
http://docs.oracle.com/javase/6/docs/api/javax/swing/JTable.html
And i dont know if there is not a better way, so you should consult API documentation and examples.
For example: http://users.csc.calpoly.edu/~jdalbey/305/Lectures/TableCellRendererExamples.html
I hope it helps you.
No, a TableCellRenderer cannot span cells. As alternatives, consider these:
TablePopupEditor, a custom TableCellEditor, can be adapted to serve as a renderer.
A ListSelectionListener, shown here, can be added to an adjacent component in order to display details of the selected row, perhaps using a JScrollPane.
I am trying to find a way to wrap text in table cells using SWT, but
I'm stuck. Does anybody know of a way to do it? Or is there a
different way to approach the problem? Basically, I have 12 columns:
6 of them are check boxes, and remaining are text fields only.
The text in the columns should be wrap automatically if the length of the size
exceeds the width of the column.
Please help me
SWT Table does not support automatic line wrapping. You can however insert newline characters yourself. See the following links for further reference:
Bug report
TableItem does not support mnemonics, wrapping, or the SWT.WRAP style.
multiline feature or wrap text feature in jface tableviewer
Java2s example
I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell. Would be very thankful.
Thanks in advance.
Several steps:
implement a custom renderer using a JTextArea as rendering component
implement a custom editor using a JTextArea inside a JScrollPane as editing component
add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification
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).