Friday, March 4, 2011

How To Masterbate With A Banana As A Male

Web Browser JComboBox column table

JComboBox column table with
We will
how we can include in a column using a JComboBox, it helps us to choose between unchanging data such as sex (male or female), year, etc.

The program will copy the name, surname and sex of the JComboBox what we choose, we can add empty rows, in this case the default sex is male. Images







Code


Master Class



Classes package;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax . swing .*;
javax.swing.table.DefaultTableModel import, import
javax.swing.table.TableColumn;


public class Main extends JApplet {

JTable table;
JComboBox sex
DefaultTableModel model;

public void init () {

nomcols []={" Name String, "" name "," Sex "};
[][]= new data String String [4] [3];
data [0] [0] = "Java"
data [0] [1] = "Zone"
data [0 ] [2] = "Male";

DefaultTableModel model = new (data, nomcols)
table = new JTable (model);

tabla.getColumnModel TableColumn col = (). GetColumn (2);

String op []={" Male "," Female "};

sex = new JComboBox (op);

col.setCellEditor (new DefaultCellEditor (sex));

JScrollPane scroll = new JScrollPane (table);

add (scroll);

pbotones JPanel = new JPanel ();
JButton add = new JButton ("Add");
agregar.addActionListener (new ActionListener () {


@ Override
public void actionPerformed (ActionEvent arg0) {
String s []={"","", "Male"};
modelo.addRow (s)
}

});

pbotones.add ( add);
add (pbotones, BorderLayout.SOUTH)

}}


As we see the code is not complicated, what we do is create a table, create a JComboBox, then we indicate that the third column will be represented with a JComboBox, this is done with the method setCellEditor (new DefaultCellEditor (sex)); TableColumn class, we have to get the TableColumn column we are interested in placing the JComboBox, we do this with tabla.getColumnModel (). GetColumn (2), with this method indicate that we want TableColumn column 3, is indicated by a 2 because the columns are numbered 0 to n-1, 3 in this case. Applet



0 comments:

Post a Comment