JTable vs. column names
I want to create a results table for my net worth program and have two problems:
1) This doesn't show the column names:
column_names = ['Type', 'Account', 'Column 3']
row_data = [
['Row 1', 'entry 1', 'entry 2'],
['Row 2', 'entry 1', 'entry 2']
]
table = JTable(DefaultTableModel(row_data, column_names))
# Neither does JTable(row_data, column_names)
The Java docs suggests:
JTable(Object[][] rowData, Object[] columnNames)
Constructs a JTable to display the values in the two dimensional array, rowData, with column names, columnNames.
The row_data gets displayed, but the column_names don't.
2) I'm looking at extract_data.py's do_extract_reminders() for hints, but it's 17 pages long on my printer. I may have missed something. :-)
This feels like either I'm doing something stupid (likely) or the Jython interface is having trouble.
I suppose it might help if I had ever used Java Swing before. I used awt in my only Java class, I think that was about 20 years ago.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Stuart Beesley ... on 08 Apr, 2021 06:54 PM
Take a look at my extract_data script for examples.
https://yogi1967.github.io/MoneydancePythonScripts/
2 Posted by Stuart Beesley ... on 08 Apr, 2021 06:55 PM
Whoops - I see you are already.... 😆 sorry. I’ll take a look but might be tomorrow.
3 Posted by hleofxquotes on 08 Apr, 2021 07:49 PM
Simplest way to fix that is to attach JTable to a JScrollPane. As in
The full class
4 Posted by Stuart Beesley ... on 08 Apr, 2021 07:59 PM
Python script... I see hleofxquotes has already replied... I had just knocked this up, so attaching anyway..
5 Posted by Stuart Beesley ... on 08 Apr, 2021 08:02 PM
PS - I didn't bother with the invokeLater() but you should for anything more than a few lines of code....
6 Posted by Ric Werme on 08 Apr, 2021 08:23 PM
Thanks guys, it would have been a while before I tried JScrollPane. Probably a finite amount of time, I figured I'd need it sooner or later.
Stuart - also on my list to investigate is running Jython code outside of Moneydance. I guess at the very least I need to find some magic path variable. (Perhaps a clue is in your invoke Moneydance shell script. Not a high priority today or even this week.)
On my Linux system, not in the Moneydance install directory:
$ python jtable.py
Traceback (most recent call last):
File "jtable.py", line 10, in <module>
from com.infinitekind.moneydance.model import *
ImportError: No module named com.infinitekind.moneydance.model
7 Posted by Stuart Beesley ... on 08 Apr, 2021 08:30 PM
Tip. Outside of Moneydance, you will need to run Jython to run Java/Jython code, not Python.. Or use something like JPype. But you will not (easily/safely) be able to access the Moneydance data outside of MD...
https://www.jython.org/download.html
8 Posted by Stuart Beesley ... on 08 Apr, 2021 08:47 PM
... as the dataset is encrypted and you need to load the moneydance libraries and ‘system’ to properly open the dataset. User @dalefurrow did have some success, but the method was advised by Sean as ‘to be avoided’. That method didn't seem to work anyway if you had set a different encryption password. However, as you will see on the next post, hleofxquotes has achieved it with some technical wizardry.
IMHO - You would be better off launching moneydance using the --invoke_and_quit method to launch MD, execute an extension, then quit.
9 Posted by hleofxquotes on 08 Apr, 2021 09:43 PM
A example showing how to run Mike's filedisplay extension as a stand-alone (without MD main UI):
Then read the README.txt
10 Posted by Ric Werme on 12 Apr, 2021 12:32 AM
Hey, lookee what I came across today in https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html :
"JTables are typically placed inside of a JScrollPane. By default, a JTable will adjust its width such that a horizontal scrollbar is unnecessary. To allow for a horizontal scrollbar, invoke setAutoResizeMode(int) with AUTO_RESIZE_OFF. Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately."
I wonder why that didn't sear into my memory when I first saw it. :-)
System closed this discussion on 12 Jul, 2021 12:40 AM.