tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/5381-jtable-vs-column-namesInfinite Kind: Discussion 2021-07-12T00:40:22Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T18:54:07Z2021-04-08T18:54:07ZJTable vs. column names<div><p>Take a look at my extract_data script for examples.</p>
<p><a href="https://yogi1967.github.io/MoneydancePythonScripts/">https://yogi1967.github.io/MoneydancePythonScripts/</a></p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T18:55:42Z2021-04-08T18:55:42ZJTable vs. column names<div><p>Whoops - I see you are already.... 😆 sorry. I’ll take a look but might be tomorrow.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T19:49:59Z2021-04-08T19:49:59ZJTable vs. column names<div><p>Simplest way to fix that is to attach JTable to a JScrollPane. As in</p>
<pre>
<code> private void initFrame(Container contentPane) {
JPanel view = new JPanel(new BorderLayout());
view.setPreferredSize(new Dimension(600, 400));
String[] columnNames = { "col1", "col2", "col3", };
String[][] data = {
{ "11", "12", "13"},
{ "21", "22", "23"},
};
JTable table = new JTable(new DefaultTableModel(data, columnNames));
JScrollPane sp = new JScrollPane(table);
view.add(sp, BorderLayout.CENTER);
contentPane.add(view);
}</code>
</pre>
<p>The full class</p>
<pre>
<code>public class ShowTableCmd extends JFrame {
public ShowTableCmd(String title) throws HeadlessException {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initFrame(getContentPane());
}
private void initFrame(Container contentPane) {
JPanel view = new JPanel(new BorderLayout());
view.setPreferredSize(new Dimension(600, 400));
String[] columnNames = { "col1", "col2", "col3", };
String[][] data = { { "11", "12", "13" }, { "21", "22", "23" }, };
JTable table = new JTable(new DefaultTableModel(data, columnNames));
JScrollPane sp = new JScrollPane(table);
view.add(sp, BorderLayout.CENTER);
contentPane.add(view);
}
public static void main(String[] args) {
final ShowTableCmd cmd = new ShowTableCmd(ShowTableCmd.class.getSimpleName());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
cmd.showMainFrame();
}
});
}
protected void showMainFrame() {
setLocation(100, 100);
pack();
setVisible(true);
}
}</code>
</pre></div>hleofxquotestag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T19:59:02Z2021-04-08T21:51:01ZJTable vs. column names<div><p>Python script... I see hleofxquotes has already replied... I had just knocked this up, so attaching anyway..</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T20:02:20Z2021-04-08T20:02:20ZJTable vs. column names<div><p>PS - I didn't bother with the invokeLater() but you should for anything more than a few lines of code....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T20:23:45Z2021-04-08T20:23:46ZJTable vs. column names<div><p>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.</p>
<p>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.)</p>
<p>On my Linux system, not in the Moneydance install directory:</p>
<p>$ python jtable.py Traceback (most recent call last):<br>
File "jtable.py", line 10, in from com.infinitekind.moneydance.model import * ImportError: No module named com.infinitekind.moneydance.model</p></div>Ric Wermetag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T20:30:07Z2021-04-09T14:08:53ZJTable vs. column names<div><p>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...</p>
<p><a href="https://www.jython.org/download.html">https://www.jython.org/download.html</a></p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T20:47:12Z2021-04-09T14:10:12ZJTable vs. column names<div><p>... 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.</p>
<p>IMHO - You would be better off launching moneydance using the --invoke_and_quit method to launch MD, execute an extension, then quit.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-08T21:43:15Z2021-04-08T21:43:15ZJTable vs. column names<div><blockquote>
<p>It doesn’t work anyway if you set a different encryption password.</p>
</blockquote>
<p>A example showing how to run Mike's filedisplay extension as a stand-alone (without MD main UI):</p>
<ul>
<li><a href="https://bitbucket.org/hleofxquotesteam/md-maven/src/master/mikerb-filedisplay/">https://bitbucket.org/hleofxquotesteam/md-maven/src/master/mikerb-f...</a></li>
<li>Download the zip file from <a href="https://bitbucket.org/hleofxquotesteam/md-maven/downloads/">https://bitbucket.org/hleofxquotesteam/md-maven/downloads/</a></li>
</ul>
<p>Then read the README.txt</p></div>hleofxquotestag:infinitekind.tenderapp.com,2009-01-14:Comment/491324672021-04-12T00:32:58Z2021-04-12T00:32:58ZJTable vs. column names<div><p>Hey, lookee what I came across today in <a href="https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html">https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html</a> :</p>
<p>"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."</p>
<p>I wonder why that didn't sear into my memory when I first saw it. :-)</p></div>Ric Werme