Java - ayuda en el manejo de jtable

 
Vista:

ayuda en el manejo de jtable

Publicado por Guillermo (5 intervenciones) el 30/11/2005 17:24:18
como hacer para tener seleccionado una fila de un jtable y apretar un boton insertar me aparesca una fila en blanco por encima de la fila que tenia seleccionada, y lo mismo cuando tengo seleccionada una fila como hacer para borrarla agradeciendoles mucho su ayuda
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda en el manejo de jtable

Publicado por Gilberto (5 intervenciones) el 30/11/2005 17:43:33
Usa getSelectedColumn, getSelectedRow para saber que columna/fila está seleccionada, removeCOlumn - removeColumnSelectionInterval/removeRowSelectionInterval para eliminar el intervalo seleccionado, addColumn+moveColumn para añadir la columna,etc.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ayuda en el manejo de jtable

Publicado por guillermo (5 intervenciones) el 02/12/2005 14:32:52
hola hago lo que me dices pero no puedo insertar una fila por encima o por debajo de mi fila seleccionada muchas gracias por la ayuda
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ayuda en el manejo de jtable

Publicado por Gilberto (5 intervenciones) el 03/12/2005 17:15:39
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.*;

/**
* @(#)Ej17.java
*
* JFC Sample application
*
* @author
* @version 1.00 05/12/03
*/
public class Ej17Frame extends JFrame {

/**
* The constructor.
*/
public Ej17Frame() {

Object[][] v = {{"Info Systems","New Tech Enterprises","Soft land","Share App Inc"},
{"Database Giant Inc","Web App Asociates","Long Soft","Sound Drivers Inc"},
{"Game Designer","RonaldSoft Inc","HiTech Asoc","Vision Asc"},
};

Object[] n = {"1987","1988","1989","1990"};
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu();
JMenuItem menuFileExit = new JMenuItem();
DefaultTableModel tablemodel = new DefaultTableModel(v,n);
JTable table = new JTable(tablemodel);
JScrollPane scrollpane = new JScrollPane(table);
JPanel panel = new JPanel();
JButton button1 = new JButton("Add Column");
JButton button2 = new JButton("Add Row");

table.setColumnSelectionAllowed(true);
table.setRowSelectionAllowed(true);
buttonListener b_listener = new buttonListener(table,tablemodel);
button1.addActionListener(b_listener);
button2.addActionListener(b_listener);

menuFile.setText("File");
menuFileExit.setText("Exit");

// Add action listener.for the menu button
menuFileExit.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
Ej17Frame.this.windowClosed();
}
}
);
menuFile.add(menuFileExit);
menuBar.add(menuFile);

panel.add(button1);
panel.add(button2);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(scrollpane,BorderLayout.CENTER);
getContentPane().add(panel,BorderLayout.SOUTH);
setTitle("Ej17Frame");
setJMenuBar(menuBar);
setSize(new Dimension(400, 400));

// Add window listener.
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Ej17Frame.this.windowClosed();
}
}
);
}


/**
* Shutdown procedure when run as an application.
*/
protected void windowClosed() {

// TODO: Check if it is safe to close the application

// Exit application.
System.exit(0);
}
}

class buttonListener implements ActionListener {

JTable table;
DefaultTableModel tablemodel;
int n;

buttonListener(JTable t,DefaultTableModel tm) {
table = t;
tablemodel = tm;
n = 0;
}

public void actionPerformed(ActionEvent e) {
if(((JButton)e.getSource()).getText().equals("Add Column")) {
int col = table.getSelectedColumn();
if(col > -1) {
table.addColumn(new TableColumn());
table.moveColumn(table.getColumnCount()-1,col);
n++;
}
}
else {
int row = table.getSelectedRow();
if(row > -1) {
tablemodel.insertRow(row,new Vector());
}
}
}

public static void main(String args[]) {
Ej17Frame frame = new Ej17Frame();

frame.setVisible(true);
}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:ayuda en el manejo de jtable

Publicado por Gilberto (5 intervenciones) el 03/12/2005 17:25:53
Hay que seleccionar una celda de la tabla antes de oprimir uno de los botones
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar