Results 1 to 8 of 8
- 08-24-2011, 09:25 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Using JTable without extending or overriding
Hello all,
I am writing a small program in Matlab. My program has a JTable in it which i have built from pure java classes. Here is a sample Matlab code (you will see that code is same with Java);
Java Code:frame=javax.swing.JFrame('table'); model=javax.swing.table.DefaultTableModel({1,'a';2,'b'},{'int','str'}); table=javax.swing.JTable(model); sorter=javax.swing.table.TableRowSorter(model); table.setRowSorter(sorter); pane=javax.swing.JScrollPane(table); frame.add(pane,java.awt.BorderLayout.CENTER); frame.setSize(300,250); frame.setVisible(true);
As you can see java objects can be used within Matlab. Now my problem is i couldnt make my table uneditable. I know that it is fairly easy doing it in Java by overriding isCellEditable method so that it returns false. However it is not possible to extend or override a Java class in Matlab (as far as i know). So i need to find another solution. Is there any other way of doing it right without overriding or extending? The only work around solution i could find is making uneditable the textfields of every columns like this;
That forbids editing but when any keyboard key is pressed, cell is entered everytime (even though it cant be edited). There is a method in cellEditor named setClickCountToStart, i gave a big number so cell cannot be entered in with mouse click but i also need to disable editing with key press now. Is it possible?Java Code:textfield=javax.swing.JTextField; textfield.setEditable(0); jtable.getColumnModel.getColumn(0).setCellEditor(javax.swing.DefaultCellEditor(textfield));
Thanks,
Arda
-
Why not create your own Java classes in Java, and then have MatLab call objects of your own classes? Then you can subclass JTable without problem.
Edit: this article tells how to integrate your custom java classes with MatLab: Integrating MatLab with Perl and JavaLast edited by Fubarable; 08-24-2011 at 10:10 PM.
- 08-24-2011, 10:17 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
I have no clue about how to that. In fact i dont know Java at all and that is why i am trying to do it in Matlab.
-
Well your first question is impossible to solve without knowing Java, and so the solution is obvious: if you want to use Java to its full capacity, your best option is to learn Java. The Java tutorials can help you with this.
- 08-25-2011, 07:13 AM #5
No, I don't see that at all. The syntax is quite different.Here is a sample Matlab code (you will see that code is same with Java);
db
- 08-25-2011, 02:40 PM #6
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
@Fubarable, thank you for your help and advice. However learning java is a long term shot (which i am confident to do). Today i need to save the day. I know it wont be easy but if you could tell me how to do (or better give some piece of code), i would at least try.
I dont know java yes, but with the help of tutorials and some example applications i have already completed other objects in my gui like menubar, splitpane, frame, etc. I have also customized my jtable except the two things; implementing a checkbox column and making my table uneditable. Using a checkbox column is a thing that i can sacrifice (if you have a solution i would be very glad though) but i have to make my table uneditable.
I even found a workaround solution to my problem as i described in my first post; setting ClickCountToStart method to 100 (or any other large number) for celleditors of every column disables editing for mouse in practice. But when i type a key it still tries to edit the cell. All i need to do is to forbid editing with keyboard. I have tried the following and it worked but now Matlab throws error every time i push a key..
So i am not comfortable with that solution, there has to be another way of doing it..Java Code:table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
- 08-26-2011, 10:35 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Does anybody know how to disable editing for a column without overriding the getColumnClass method or extending the AbstractTableModel?
I would be really appreciated for some help..
-
Last edited by Fubarable; 08-29-2011 at 04:25 AM.
Similar Threads
-
Confused about Overriding - Please Help
By jazzermonty in forum New To JavaReplies: 15Last Post: 01-24-2011, 05:20 PM -
Extending Classes and What is Necessary
By GavinCash in forum New To JavaReplies: 10Last Post: 10-11-2010, 07:07 AM -
Overriding
By prasanna1157 in forum New To JavaReplies: 7Last Post: 09-07-2010, 07:47 AM -
Overriding
By renuka_renukut in forum Advanced JavaReplies: 3Last Post: 05-21-2010, 08:45 AM -
Implementing and Extending together
By eva in forum New To JavaReplies: 2Last Post: 12-24-2007, 09:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks