Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Cursor positon within JTable
Saket Barve
Ranch Hand
Posts: 237
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There's a scenario where I explicitly add rows to a table and am then required to set the cursor in the first column of this newly added row.
Once the row is set into the table model, I am making use of the following code to do the needful:
table.changeSelection( row, 0, false, false ); table.setCursor( new Cursor(Cursor.DEFAULT_CURSOR) ); table.requestFocusInWindow();
However, this code block merely makes the newly added row
selected
without any trace of the cursor. How may I tackle this?
Thanks,
Saket
Michael Dunn
Ranch Hand
Posts: 4632
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; class Testing { public void buildGUI() { final JTable table = new JTable(5,5); JScrollPane sp = new JScrollPane(table); JButton btn = new JButton("Add New Row"); JFrame f = new JFrame(); f.getContentPane().add(sp,BorderLayout.CENTER); f.getContentPane().add(btn,BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ ((DefaultTableModel)table.getModel()).addRow(new String[]{"","","","",""}); table.editCellAt(table.getRowCount()-1,0); Component editor = table.getEditorComponent(); editor.requestFocusInWindow(); } }); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ new Testing().buildGUI(); } }); } }
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Select vs Edit in JTable
How to focus a particular cell in JTable
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
multiple inserts with multiple connections into same db table.
How to find the size of my resultSet
More...