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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Swing / AWT / SWT
Scrollbar not move down in JTable
CongSon Nguyen
Greenhorn
Posts: 4
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
When I add a new data row to the table, the scrollbar keeps staying at the same place (not move down). Here's the code:
package nhap; import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class ModelJTable extends JFrame { private DefaultTableModel model; private JTable table; public ModelJTable() { super(); model = new DefaultTableModel(); model.addColumn("First Name"); model.addColumn("Last Name"); model.addColumn("Years"); String[] socrates = { "Socrates", "", "469-399 B.C." }; model.addRow(socrates); String[] plato = { "Plato", "", "428-347 B.C." }; model.addRow(plato); String[] aquinas = { "Thomas", "Aquinas", "1225-1274" }; model.addRow(aquinas); String[] kierkegaard = { "Soren", "Kierkegaard", "1813-1855" }; model.addRow(kierkegaard); String[] kant = { "Immanuel", "Kant", "1724-1804" }; model.addRow(kant); String[] nietzsche = { "Friedrich", "Nietzsche", "1844-1900" }; model.addRow(nietzsche); String[] arendt = { "Hannah", "Arendt", "1906-1975" }; model.addRow(arendt); table = new JTable(model); JButton addButton = new JButton("Add Philosopher"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String[] philosopher = { "", "", "" }; model.addRow(philosopher); } }); JButton removeButton = new JButton("Remove Selected Philosopher"); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { model.removeRow(table.getSelectedRow()); } }); JPanel inputPanel = new JPanel(); inputPanel.add(addButton); inputPanel.add(removeButton); Container container = getContentPane(); container.add(new JScrollPane(table), BorderLayout.CENTER); container.add(inputPanel, BorderLayout.NORTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 200); //pack(); setVisible(true); } public static void main(String args[]) { new ModelJTable(); } }
How can I make the scrollbar go down ? I tried to search Google for answer, but so far I've not found any one. Thanks for your help.
Rob Camick
Rancher
Posts: 3324
32
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Cross posted:
http://forums.oracle.com/forums/thread.jspa?threadID=2131833&tstart=0
Be Forthright When Cross Posting To Other Sites
CongSon Nguyen
Greenhorn
Posts: 4
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks, Rob Camick. I'm sorry.
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Selecting cells in JTable
URGENT PLz
GUI control
Jtable
JTable doesn't refresh :(
More...