![]() |
Add button to every new jtable row during runtime
hi all i have been give a task to add button of delete and update to every row of the jtable ! for example if a new row is added add and update button should be added along them ! any help will be appreciated thanx in advance:confused:
|
Re: Add button to every new jtable row during runtime
Hi.
How about showing us the code you use to create your table, with your attempt at adding the button. Here's hint - you are going to need two more columns in each row, one for add and one for update. That's one possible solution, but yours might differ. In general, people won't help you unless you put in some effort, so at the very least, share your code, nobody will laugh at your efforts, they just want to see that you've really tried to do the work first. Good luck, Ewald |
Re: Add button to every new jtable row during runtime
Hi m glad that u people are here to help . so far im able to add buttons to two of my columns, but the problem is that im unable to give them sepereate name and also I m unable to make them delete and update the particular row ! I have code to update n delete the row but I’m unable to use that code for buttons inside the jtable ! I m going to past the code of gui and cell renders n editors , also for delete button and edit buttons actions code which they should perform when they are pressed….plz help me n edit them so that
1.they show distant name according to their columns. Delete column should show buttons with delete written on them 2.i show distant name according to their columns. edit column should show buttons with edit written on them. 3.perform deletion n update function each of their respective rows. |
Re: Add button to every new jtable row during runtime
]
Code:
|
Re: Add button to every new jtable row during runtime
]
Code:
/*Code:
private void UpdateMouseClicked(java.awt.event.MouseEvent evt) { |
Re: Add button to every new jtable row during runtime
Code:
public class NewJFrame extends javax.swing.JFrame { |
Re: Add button to every new jtable row during runtime
Hi.
I think you might be better served if you attached the code in a ZIP archive, that way whoever helps you can be sure to get it right. You are going to have to put the buttons in some kind of ARRAY, or LIST : upload the code in the ZIP and I'll take a look at it. Best regards, Ewald |
Re: Add button to every new jtable row during runtime
1 Attachment(s)
hi ok im going to attach the rar file ! i have set name to them now the problem is that i want to add the actionlistner .....thanx in advance
|
Re: Add button to every new jtable row during runtime
Awesome!
You are very close to an answer. I don't think giving you exact code is going to help you learn something, but I have a handy hint for you that's going to push you in the right direction: The following section of code displays a main panel, filled with some buttons. If you click on one, it identifies itself. The buttons are added to a list at runtime, so, in theory, you can have as many buttons as you want. Using this, you can do the same in your code. Believe it or not, this piece of code creates 150 buttons :) Please let me know if you managed to get your code working. Best regards, Ewald package lotsofbuttons; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedList; import java.util.List; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class LotsOfButtons extends JFrame implements ActionListener { private static final int BUTTONS = 150; private List<JButton> buttons = new LinkedList<JButton>(); public LotsOfButtons() { setupFrame(); setupButtons(); } protected void setupFrame() { this.setSize(640, 480); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); this.setLayout(new FlowLayout(FlowLayout.LEFT)); } /** * Create all of our buttons, add the action listener, * add them to the list and then add them to the main panel. */ protected void setupButtons() { for (int i = 0; i < BUTTONS; i++) { JButton button = new JButton("" + i); button.addActionListener(this); buttons.add(button); this.add(button); } } /** * @param args the command line arguments */ public static void main(String[] args) { LotsOfButtons app = new LotsOfButtons(); app.setVisible(true); } /** * Loop through all our buttons, if it's the one * that was clicked, display the correct message * @param e */ public void actionPerformed(ActionEvent e) { for (JButton jButton : buttons) { if (e.getSource().equals(jButton)) { JOptionPane.showMessageDialog(this, "You pressed " + jButton.getText()); break; } } } } |
Re: Add button to every new jtable row during runtime
no it didn't ring a bell :nonod::nonod:adding buttons is working fine .but giving them separate actionlister is difficult just give me hint where n how to put actionlistner in my code m stuck in it :embarasse.for example when i press the delete button of particular row it deletes it.and when i press the update button of particular row it should let me do hat i want to do... plz help me in a way that i should learn something . i agree with u that giving me exact code is not a good idea but atleast make me move in right direction .:confused:
|
| All times are GMT +5.5. The time now is 04:07. |