Results 1 to 7 of 7
Thread: JButtons and JTables
- 02-19-2013, 05:19 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
JButtons and JTables
Hi,
I decided to add JButtons in a JTable (it's actually a DefaultTableModel). but instead of a normal button I see "javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,bor der=javax.swing.plaf.BorderUIResource$CompoundBord erUIResource@371d1794,flags=296,maximumSize=,minim umSize=,preferredSize=,defaultIcon=,disabledIcon=, disabledSelectedIcon=,margin=javax.swing.plaf.Inse tsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rol loverEnabled=true,rolloverIcon=,rolloverSelectedIc on=,selectedIcon=,text=verwijder,defaultCapable=tr ue]". Does someone know a solution? I use this code:
Java Code:package View; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.RowSorter; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; public class PanelView extends JPanel{ private static final long serialVersionUID = 1L; protected JTable table; protected JScrollPane pane; DefaultTableModel model; public PanelView(){ } public void makeTabel() { System.out.println("tabel maken"); try { for(Object[] o: file.getList()) { addRowIntoTable(o); } } catch(NullPointerException e) { } } //don't mind this, it only makes a table and that works /*public void createTable(String columns[], Object rows[][]){ model = new DefaultTableModel(rows, columns) { public Class getColumnClass(int column) { Class returnValue; if ((column >= 0) && (column < getColumnCount())) { returnValue = getValueAt(0, column).getClass(); } else { returnValue = Object.class; } return returnValue; } }; JTable table = new JTable(model); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); pane = new JScrollPane(table); }*/ public void addRowIntoTable(Object row[]) { model.insertRow(model.getRowCount(), row); } }This isn't all of the code: some date is loaded from a file and put into the table.Java Code:package View; import javax.swing.JButton; public class PanelBand extends PanelView { private static final long serialVersionUID = 1L; public PanelBand(String map){ String columns[] = {"test","test","test","test"}; JButton button = new JButton("verwijder"); Object row[] = {"test","test","test",button}; Object rows[][] = {}; createTable(columns, rows); makeTabel(); add(pane); } }
Thanks!
- 02-19-2013, 05:49 PM #2
Re: JButtons and JTables
You can't just add a JButton to a JTable. What you're seeing is what happens when the JButton's toString() method is called, because the JTable is trying to render the JButton as a JTable.
Instead, you'll want to use a custom renderer that draws a JButton. Keep in mind that these JButtons won't accept click events.
You might also want to rethink our logic here. Do you really want a JTable of JButtons? Or do you want a grid of JButtons (if so use a layout manager)? Or do you want a JTable that supports mouse input (if so use a MouseListener)?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-19-2013, 06:53 PM #3
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
- 02-19-2013, 07:12 PM #4
Re: JButtons and JTables
Like I said, you can either use a custom renderer or a MouseListener, or even both.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-20-2013, 02:38 PM #5
Re: JButtons and JTables
Check out camickr's http://tips4java.wordpress.com/2009/...button-column/
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-20-2013, 02:39 PM #6
Re: JButtons and JTables
Moved from Advanced Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-20-2013, 06:39 PM #7
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
JLists and JTables
By loopsnhoops in forum New To JavaReplies: 2Last Post: 05-27-2011, 01:19 AM -
Jtables
By amiral.smith in forum AWT / SwingReplies: 1Last Post: 01-28-2011, 03:22 PM -
JTables and Databases
By sehudson in forum Advanced JavaReplies: 8Last Post: 03-25-2010, 09:01 AM -
CheckBoxes and JTables
By lakshayghai in forum AWT / SwingReplies: 1Last Post: 03-16-2010, 08:01 PM -
Scrolling with JTables
By hiranya in forum AWT / SwingReplies: 5Last Post: 10-30-2007, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks