bueno creo q la pregunta no quedo muy clara que digamos ... jajaja por otra parte les comento que el problema era q el evento clik del Jtable solo se lanzaba cuando se hacia click sobre una fila ya insertada, esto no me funcionaba por q io lo utilizaria para insertar filas.. jaja bueno . . creo q no me esplico muy bien asi q me remito directo al codigo Ya funciona la solucion se encuentra en las propiedades del Jtable gracias de todos modos a todos.. les dejo el codigo,, shi toy incluyrndo un boton en el PopupMenu. con du respectivo evento click si alguien tiene alguna mejora... se agradece
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJDialog.java
*
* Created on 12-02-2010, 08:44:07 PM
*/
package javaapplication3;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.plaf.ButtonUI;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
/**
*
* @author sk
*/
public class NewJDialog extends javax.swing.JDialog {
JPopupMenu pop = new JPopupMenu();
/** Creates new form NewJDialog */
public NewJDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
JMenuItem findMenuItem = new JMenuItem("Opciones");
pop.add(findMenuItem);
JMenuItem menuItem = new JMenuItem("Adicionar Repuesto");
JButton btnalgo = new JButton("butono");
// btnalgo.setSize(50, 50);
btnalgo.setText("Adicionar Repuesto");
btnalgo.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnalgoClicked(evt);
}
});
//btnalgo.setPreferredSize(new Dimension(150, 150));
//btnalgo.setMinimumSize(new Dimension(150, 150));
menuItem.add(btnalgo);
menuItem.setSize(120, 120);
pop.add(menuItem);
// jTable1.setEnabled(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Jpcontenedor = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
Jpcontenedor.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
JpcontenedorMouseClicked(evt);
}
});
Jpcontenedor.setLayout(new javax.swing.BoxLayout(Jpcontenedor, javax.swing.BoxLayout.LINE_AXIS));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jTable1.setFillsViewportHeight(true);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
Jpcontenedor.add(jScrollPane1);
jButton1.setText("jButton1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Jpcontenedor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(245, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(82, 82, 82))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addComponent(Jpcontenedor, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void JpcontenedorMouseClicked(java.awt.event.MouseEvent evt) {
String h = "h";
if (evt.getButton() == MouseEvent.BUTTON3 && evt.MOUSE_CLICKED == MouseEvent.MOUSE_CLICKED) {
//JMenuItem pasteMenuItem = new JMenuItem("Paste");
// pasteMenuItem.setEnabled(false);
// ButtonUI a = new BasicButtonUI();
//pasteMenuItem.setUI(a);
// pop.add(pasteMenuItem);+
//jTable1.setComponentPopupMenu(pop);
}
}
@SuppressWarnings("static-access")
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
String h = "h";
if (evt.getButton() == MouseEvent.BUTTON3 && evt.MOUSE_CLICKED == MouseEvent.MOUSE_CLICKED) {
jTable1.setComponentPopupMenu(pop);
}
}
DefaultTableModel model = null;
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String fila[] = {"expe"+model.getRowCount(), "expe", "expe"};
model.addRow(fila);
}
private void btnalgoClicked(java.awt.event.MouseEvent evt) {
// JOptionPane.showInputDialog("ok");
String data[][] = {{"Vinod", "100", ""}, {"", "Raju", "200"}, {"Ranju", "", "300"}};
String col[] = {"Name", "code", ""};
ArrayList<String> list = new ArrayList<String>();
//DefaultTableModel asdf = new DefaultTableModel(
model = new DefaultTableModel(data, col);
jTable1.setModel(model);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel Jpcontenedor;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJDialog.java
*
* Created on 12-02-2010, 08:44:07 PM
*/
package javaapplication3;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.plaf.ButtonUI;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
/**
*
* @author sk
*/
public class NewJDialog extends javax.swing.JDialog {
JPopupMenu pop = new JPopupMenu();
/** Creates new form NewJDialog */
public NewJDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
JMenuItem findMenuItem = new JMenuItem("Opciones");
pop.add(findMenuItem);
JMenuItem menuItem = new JMenuItem("Adicionar Repuesto");
JButton btnalgo = new JButton("butono");
// btnalgo.setSize(50, 50);
btnalgo.setText("Adicionar Repuesto");
btnalgo.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnalgoClicked(evt);
}
});
//btnalgo.setPreferredSize(new Dimension(150, 150));
//btnalgo.setMinimumSize(new Dimension(150, 150));
menuItem.add(btnalgo);
menuItem.setSize(120, 120);
pop.add(menuItem);
// jTable1.setEnabled(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Jpcontenedor = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
Jpcontenedor.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
JpcontenedorMouseClicked(evt);
}
});
Jpcontenedor.setLayout(new javax.swing.BoxLayout(Jpcontenedor, javax.swing.BoxLayout.LINE_AXIS));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jTable1.setFillsViewportHeight(true);
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
Jpcontenedor.add(jScrollPane1);
jButton1.setText("jButton1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Jpcontenedor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(245, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(82, 82, 82))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addComponent(Jpcontenedor, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void JpcontenedorMouseClicked(java.awt.event.MouseEvent evt) {
String h = "h";
if (evt.getButton() == MouseEvent.BUTTON3 && evt.MOUSE_CLICKED == MouseEvent.MOUSE_CLICKED) {
//JMenuItem pasteMenuItem = new JMenuItem("Paste");
// pasteMenuItem.setEnabled(false);
// ButtonUI a = new BasicButtonUI();
//pasteMenuItem.setUI(a);
// pop.add(pasteMenuItem);+
//jTable1.setComponentPopupMenu(pop);
}
}
@SuppressWarnings("static-access")
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
String h = "h";
if (evt.getButton() == MouseEvent.BUTTON3 && evt.MOUSE_CLICKED == MouseEvent.MOUSE_CLICKED) {
jTable1.setComponentPopupMenu(pop);
}
}
DefaultTableModel model = null;
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String fila[] = {"expe"+model.getRowCount(), "expe", "expe"};
model.addRow(fila);
}
private void btnalgoClicked(java.awt.event.MouseEvent evt) {
// JOptionPane.showInputDialog("ok");
String data[][] = {{"Vinod", "100", ""}, {"", "Raju", "200"}, {"Ranju", "", "300"}};
String col[] = {"Name", "code", ""};
ArrayList<String> list = new ArrayList<String>();
//DefaultTableModel asdf = new DefaultTableModel(
model = new DefaultTableModel(data, col);
jTable1.setModel(model);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel Jpcontenedor;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}