Power Table - Text Entry Question Concerning Text Wrap

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.

1 Like

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.
powertable

1 Like

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.

1 Like

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.

  1. 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?

  2. 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.