Displaying text wrap in our Power Table is working fine.
How or can we apply text wrap when an operator is entering text. The pic below is what our tables currently look like.
Displaying text wrap in our Power Table is working fine.
How or can we apply text wrap when an operator is entering text. The pic below is what our tables currently look like.
Youâd have to implement a custom table cell editor, thatâs using something like a JTextArea rather than a JTextField. Youâll have to be moderately comfortable in Java Swing.
Iâm not experienced with Java Swing.
So I can do some experimenting, where is this custom table editor? Would I put it in the Component Scripting under Extension Function configureCell or is this something completely different?
configureEditor
, rather than configureCell
. You need to return some implementation of the TableCellEditor
interface. Java comes with a DefaultCellEditor
, but it only supports using a combobox, a check box, or a text field, which can only edit a single line. I looked through our codebase, but couldnât find anywhere weâre creating a multiline cell editor that you could just import, so youâd have to do it yourself.
Thank you.
I found a Topic you helped someone else solve that had to do with Java.Swing.
I've been experimenting with this advice and attempting to understand the teaching from JavaTpoint tutorial.
Yeah, thatâs the rough model. One problem is that you wonât be able to subclass DefaultCellEditor
directly, so youâll have to subclass TableCellEditor
(or AbstractCellEditor
) directly and implement the required methods.
PGriffith, If you have a moment I could use a hand with this one. Itâs not crucial to the project but it is bugging me. Iâve been âplayingâ with the javax.swing TableCellEditor and Iâm receiving no errors but Iâm also not getting the results Iâm after.
The script below is in my current PowerTableâs Component Scripting configureEditor.
I have stripped it down to what I think is the bare minimum (believe me, it grew and got jumbled in a hurry).
Can you steer me in the right direction?
from javax.swing import TableCellEditor, JTextArea
from java.swing import LineWrap
if self.data.getColumnType(colName) == 'note':
return {'editor': TableCellEditor(JTextArea(5, 20), setLineWrap(true), setWrapStyleWord(true))}
Theoretically, it would look something more like this. Disclaimer: completely untested.
from javax.swing import AbstractCellEditor, JTextArea
if self.data.getColumnType(colName) == 'note':
class CustomEditor(AbstractCellEditor):
def __init__(self):
self.component = JTextArea(5, 20)
self.component.lineWrap = True
self.component.wrapStyleWord = True
def getTableCellEditorComponent(self, table, value, selected, row, column):
self.component.text = value
return self.component
def getCellEditorValue(self):
return self.component.text
return {'editor': CustomEditor()}
Shoot, no luck. I also tried a few variations of your suggestion, above. No errors but not wrapping the text.
If you come up with a solution I would love to see it and use it. Thank you
Huh, actually, âworkedâ without too much trouble. Once you applied the script, try closing and re-opening the window with the power table - just saving changes doesnât seem to fire configureEditor
consistently.
from javax.swing import AbstractCellEditor, JTextArea
from javax.swing.table import TableCellEditor
# if self.data.getColumnType(colName) == 'note':
class CustomEditor(AbstractCellEditor, TableCellEditor):
def __init__(self):
self.component = JTextArea(5, 20)
self.component.lineWrap = True
self.component.wrapStyleWord = True
def getTableCellEditorComponent(self, table, value, selected, row, column):
self.component.text = value
return self.component
def getCellEditorValue(self):
return self.component.text
return {'editor': CustomEditor()}
Still doesnât quite handle multilines correctly on re-insert, but itâs closer.
Yes. This is definitely a step fwd . Thank you.
Iâm curious, when we set self.component = JTextArea(5,20)
I thought we were defining 5 lines of 20 characters. I seem to be able to add many lines(rows) of way more than 20 characters.
That establishes the "preferred size" for display without scrollbars--not a content restriction. And that size is ignored when stuck in a table cell.
I have to ask some more questions, Iâm simply not going to be able to solve these on my own.
The example above is working well. It just needs a few refinements before I can put it out on the plant floor, plus I think other users will benefit from this Topic.
Two main enhancements for now.
How can we make the Power Tableâs Cell expand as data is being typed in?
For Example, An operator is typing away and gets to the end(far Right side) of the Power Tableâs
Text area the Typed text is received but is not displayed until they click outside of the text area. That
is when the cell expands and text wraps. I guess a simpler way of putting it is how would we make
the text wrap active while the operator is typing?
How can we make it so the typed in text is entered using the Tab Key? Right now the Enter Key
creates a new line within the text area and the tab key is working to tab text over.
The only thing that seems to enter the text or update the table is to mouse click another cell in the
table. What is a standard for text area enter?
Thank you in advance.