I have a jtextfield above each column header with which I am trying to filter on numbers like > numb, < num, !num, ==num, <=num, >=num.
For example if I enter >=100 in the jtextfield by splitting it should fetch me filtered results of numbers greater than or equal to 100.
I have used many if else conditions inside a button action listener method but after few if else the others are not working fine,but when run separately it's working. How to resolve this?
import javax.swing.RowFilter.ComparisonType;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.*;
public class TableFilter {
public TableFilter() {
Object[][] rows
= {{100, "Aaa",10},
{101, "Bbb",11},
{102, "Ccc",5},
{103, "Ddd",3},
{104, "Eee",2},
{105, "Fff",5},
{106, "Ggg",11},
{107, "Hhh",8} };
String[] column = {"empno", "name","experience"};
TableModel model = new DefaultTableModel(rows, column) {
public Class getColumnClass(int column) {
Class returnValue;
if ((column >= 0) && (column < getColumnCount())) {
returnValue = getValueAt(0, column).getClass();
} else {
returnValue = Object.class;
}
return returnValue;
}
};
final JTable table = new JTable(model);
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table.setRowSorter(sorter);
JTextField jtf1 = new JTextField(5);
JTextField jtf2 = new JTextField(5);
JTextField jtf3 = new JTextField(5);
JButton b1 = new JButton ("ENTER");
///////////////////EQUAL
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = jtf1.getText();
if (text.length() == 0) {
sorter.setRowFilter(null);
}
else if(text.startsWith("="))
{
String[] parts = text.split("=");
String part1 = parts[1];
sorter.setRowFilter(RowFilter.regexFilter(part1));}
else if(text.startsWith("!"))
{
String[] parts = text.split("!");
String part1 = parts[1];
sorter.setRowFilter(RowFilter.notFilter(RowFilter.regexFilter(part1)));
}
else if(text.startsWith(">"))
{
String[] parts = text.split(">");
String part1 = parts[1];
sorter.setRowFilter(RowFilter.numberFilter(ComparisonType.AFTER, Integer.parseInt(part1)));
}
else if(text.startsWith("<"))
{
//System.out.println("*****************");
String[] parts = text.split("<");
String part1 = parts[1];
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
Number numb=Integer.parseInt(part1);
filters.add(0,RowFilter.notFilter(RowFilter.numberFilter(ComparisonType.AFTER,numb)));
filters.add(0,RowFilter.notFilter(RowFilter.numberFilter(ComparisonType.EQUAL,numb)));
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
TableRowSorter<DefaultTableModel> tr = new TableRowSorter<>(dtm);
table.setRowSorter(tr);
RowFilter<Object, Object> rf = RowFilter.andFilter(filters);
tr.setRowFilter(rf);
}
else if(text.startsWith(">="))
{
System.out.println("*****************");
String[] p1=text.split(">");
String p2=p1[1];
String[] p3=p2.split("=");
String pf=p3[1];
Number numb=Integer.parseInt(pf);
// String s=text.substring(2);
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(0,RowFilter.numberFilter(ComparisonType.EQUAL,numb));
filters.add(0,RowFilter.numberFilter(ComparisonType.AFTER,numb));
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
TableRowSorter<DefaultTableModel> tr = new TableRowSorter<>(dtm);
table.setRowSorter(tr);
RowFilter<Object, Object> rf = RowFilter.orFilter(filters);
tr.setRowFilter(rf);
}
else if(text.startsWith("<="))
{
String[] p1=text.split("<");
String p2=p1[1];
String[] p3=p2.split("=");
String pf=p3[1];
//Number numb=Integer.parseInt(pf);
//String sub=text.substring(2);
sorter.setRowFilter(RowFilter.notFilter(RowFilter.numberFilter(ComparisonType.AFTER, Integer.parseInt(pf))));
}
}
}
);
JPanel panel = new JPanel(new FlowLayout());
panel.add(jtf1);
panel.add(Box.createHorizontalStrut(350));
panel.add(jtf2);
panel.add(Box.createHorizontalStrut(350));
panel.add(jtf3);
panel.add(Box.createHorizontalStrut(150));
panel.add(b1);
JFrame frame = new JFrame();
frame.add(panel, BorderLayout.BEFORE_FIRST_LINE);
frame.add(new JScrollPane(table), BorderLayout.CENTER);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TableFilter();
}
});
}
}
Following code will definitely resolve your problem.
b1.addActionListener(new ActionListener() {
private List<String> operaters=Arrays.asList(new String []{">", "<", "!", "==", "<=", ">="});
private String filterPattern="[0-9]|[A-Z]|[a-z]|[0-9]";
public void actionPerformed(ActionEvent e) {
applyFilter(jtf1.getText(),0);
}
private void applyFilter(String text,int columnIndex) {
if (text.length() == 0) {
//sorter.setRowFilter(null);
}else{
String operator=text.toString().split(filterPattern)[0];
if(operaters.contains(operator)){
String value=text.split(operator).length>1?text.split(operator)[1]:"";
sorter.setRowFilter(getRowFilter(operator,value,columnIndex));
}
}
}
private RowFilter<? super TableModel, ? super Integer> getRowFilter(
String operator, String value,int columnIndex) {
if (operator.equals("==")) {
return RowFilter.regexFilter(value);
} else if (operator.equals("!")) {
return RowFilter.notFilter(RowFilter.regexFilter(value,columnIndex));
}
else if (operator.equals(">")) {
return RowFilter.numberFilter(ComparisonType.AFTER,
Integer.parseInt(value),columnIndex);
} else if (operator.equals("<")) {
Number numb = Integer.parseInt(value);
return RowFilter.numberFilter(ComparisonType.BEFORE, numb,columnIndex);
} else if (operator.equals(">=")) {
Number numb = Integer.parseInt(value);
// String s=text.substring(2);
List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(
2);
filters.add(0,
RowFilter.numberFilter(ComparisonType.EQUAL, numb,columnIndex));
filters.add(0,
RowFilter.numberFilter(ComparisonType.AFTER, numb,columnIndex));
return RowFilter.orFilter(filters);
}
else if (operator.equals("<=")) {
Number numb = Integer.parseInt(value);
// String s=text.substring(2);
List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(
2);
filters.add(0,
RowFilter.numberFilter(ComparisonType.EQUAL, numb,columnIndex));
filters.add(0,
RowFilter.numberFilter(ComparisonType.BEFORE, numb,columnIndex));
return RowFilter.orFilter(filters);
}
return null;
}
}
);
Related
So I think I need to split my scroll pane list because it's over 100 items I want to display. I was thinking I could have a scroll pane with tabs with each of the tabs having different parts of the list. Kind of like a tabbed pane, but just for the scroll pane like it's just one component. The problem is I don't know how to do this or if it is possible.
Here is an example which displays the MIDI instruments for all banks in a JTable. Above it offers three combo boxes (JComboBox) and a JTextField.
The text field can search (case insensitive) for any string the user enters.
The combos can be used to filter for:
Categories of instruments.
Types of instruments.
Common strings in instrument names.
Oh, and I threw in a JList of the categories. It does nothing, but if I was doing this over, I'd start with, and only have, the list in the LINE_START position.
import java.awt.*;
import java.awt.event.*;
import javax.sound.midi.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.EmptyBorder;
public class MidiInstrumentSearch {
private JComponent ui = null;
Instrument[] instruments;
JLabel messageLabel = new JLabel("Message Label");
JTable table;
MidiInstrumentTableModel tm;
TableRowSorter sorter;
InstrumentCategory[] instrumentCategories = {
new InstrumentCategory("All", 1, 10000),
new InstrumentCategory("Piano", 1, 8),
new InstrumentCategory("Chromatic Percussion", 9, 16),
new InstrumentCategory("Organ", 17, 24),
new InstrumentCategory("Guitar", 25, 32),
new InstrumentCategory("Bass", 33, 40),
new InstrumentCategory("Strings", 41, 48),
new InstrumentCategory("Ensemble", 49, 56),
new InstrumentCategory("Brass", 57, 64),
new InstrumentCategory("Reed", 65, 72),
new InstrumentCategory("Pipe", 73, 80),
new InstrumentCategory("Synth Lead", 81, 88),
new InstrumentCategory("Synth Pad", 89, 96),
new InstrumentCategory("Synth Effects", 97, 104),
new InstrumentCategory("Ethnic", 105, 112),
new InstrumentCategory("Percussive", 113, 120),
new InstrumentCategory("Sound Effects", 121, 128)
};
MidiInstrumentSearch() {
try {
initUI();
} catch (MidiUnavailableException ex) {
ex.printStackTrace();
}
}
public final void initUI() throws MidiUnavailableException {
if (ui != null) {
return;
}
ui = new JPanel(new BorderLayout(4, 4));
ui.setBorder(new EmptyBorder(4, 4, 4, 4));
ui.add(messageLabel, BorderLayout.PAGE_END);
ui.add(new JScrollPane(new JList(instrumentCategories)),
BorderLayout.LINE_START);
Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
instruments = synthesizer.getAvailableInstruments();
InstrumentPOJO[] inst = new InstrumentPOJO[instruments.length];
for (int ii = 0; ii < inst.length; ii++) {
inst[ii] = new InstrumentPOJO(instruments[ii]);
}
tm = new MidiInstrumentTableModel(inst);
sorter = new TableRowSorter<>(tm);
table = new JTable(tm);
table.setRowSorter(sorter);
ui.add(new JScrollPane(table));
JToolBar toolBar = new JToolBar();
toolBar.setLayout(new FlowLayout());
ui.add(toolBar, BorderLayout.PAGE_START);
final JComboBox categoryBox = new JComboBox<>(instrumentCategories);
ActionListener categoryListener = (ActionEvent e) -> {
InstrumentCategory ic = (InstrumentCategory) categoryBox.getSelectedItem();
CategoryFilter categoryFilter = new CategoryFilter(ic);
sorter.setRowFilter(categoryFilter);
setNumber();
};
categoryBox.addActionListener(categoryListener);
toolBar.add(new JLabel("Category"));
toolBar.add(categoryBox);
toolBar.add(new JLabel("Type"));
String[] types = {"", "Instrument", "Drumkit"};
final JComboBox typeBox = new JComboBox<>(types);
toolBar.add(typeBox);
ActionListener typeSearchListener = (ActionEvent e) -> {
String s = typeBox.getSelectedItem().toString();
SearchFilter sf = new SearchFilter(0, s);
sorter.setRowFilter(sf);
setNumber();
};
typeBox.addActionListener(typeSearchListener);
String[] nameCommon = {
"", "bass", "bell", "brass", "bs",
"drum", "flute", "gt", "harp", "horn",
"org", "orch", "pad", "piano",
"sax", "str", "syn", "vox", "wave"
};
final JComboBox nameBox = new JComboBox(nameCommon);
ActionListener nameListener = (ActionEvent e) -> {
SearchFilter sf = new SearchFilter(1, nameBox.getSelectedItem().toString());
sorter.setRowFilter(sf);
setNumber();
};
nameBox.addActionListener(nameListener);
toolBar.add(new JLabel("Name"));
toolBar.add(nameBox);
JTextField searchField = new JTextField("Enter to Search", 12);
toolBar.add(searchField);
ActionListener textSearchListener = (ActionEvent e) -> {
SearchFilter sf = new SearchFilter(1, e.getActionCommand());
sorter.setRowFilter(sf);
setNumber();
};
searchField.addActionListener(textSearchListener);
}
private void setNumber() {
int i = table.getRowCount();
setNumber(i);
}
private void setNumber(int n) {
messageLabel.setText(n + " presets");
}
public JComponent getUI() {
return ui;
}
public static void main(String[] args) {
Runnable r = () -> {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception useDefault) {
}
MidiInstrumentSearch o = new MidiInstrumentSearch();
JFrame f = new JFrame(o.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
f.setContentPane(o.getUI());
f.pack();
f.setMinimumSize(f.getSize());
f.setVisible(true);
};
SwingUtilities.invokeLater(r);
}
}
class InstrumentPOJO {
private final Instrument instrument;
private final String category;
private final String name;
private final int bank;
private final int preset;
InstrumentPOJO(Instrument instrument) {
this.instrument = instrument;
String s = instrument.toString();
category = getTextBetween(s, "", ":");
name = getTextBetween(s, ":", "bank");
bank = Integer.parseInt(getTextBetween(s, "bank #", " preset"));
String pre = "preset #";
int index = s.indexOf(pre);
s = s.substring(index + pre.length());
preset = Integer.parseInt(s);
}
private String getTextBetween(String s, String s1, String s2) {
int i1 = s.indexOf(s1);
int c1 = i1 + s1.length();
int i2 = s.indexOf(s2);
return s.substring(c1, i2).trim();
}
#Override
public String toString() {
return getCategory() + " \t"
+ getName() + " \t"
+ getBank() + " \t"
+ getPreset() + " \t";
}
public Instrument getInstrument() {
return instrument;
}
public String getCategory() {
return category;
}
public String getName() {
return name;
}
public int getBank() {
return bank;
}
public int getPreset() {
return preset;
}
}
class MidiInstrumentTableModel extends AbstractTableModel {
final static String[] colNames = {"Category", "Name", "Bank", "Preset"};
InstrumentPOJO[] orchestra;
MidiInstrumentTableModel(InstrumentPOJO[] orchestra) {
this.orchestra = orchestra;
}
#Override
public int getRowCount() {
return orchestra.length;
}
#Override
public int getColumnCount() {
return 4;
}
#Override
public Object getValueAt(int rowIndex, int columnIndex) {
final InstrumentPOJO ip = orchestra[rowIndex];
switch (columnIndex) {
case 0:
return ip.getCategory();
case 1:
return ip.getName();
case 2:
return ip.getBank();
case 3:
return ip.getPreset();
default:
return null;
}
}
#Override
public String getColumnName(int columnIndex) {
return colNames[columnIndex];
}
#Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return String.class;
case 1:
return String.class;
case 2:
return Integer.class;
case 3:
return Integer.class;
default:
return Integer.class;
}
}
#Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
class SearchFilter extends RowFilter {
int col;
String target;
SearchFilter(int col, String target) {
this.col = col;
this.target = target;
}
#Override
public boolean include(Entry entry) {
String s = entry.getValue(col).toString();
return s.toLowerCase().contains(target.toLowerCase());
}
}
class CategoryFilter extends RowFilter {
InstrumentCategory cat;
CategoryFilter(InstrumentCategory cat) {
this.cat = cat;
}
#Override
public boolean include(Entry entry) {
int i = (Integer) entry.getValue(3) + 1;
return (i >= cat.getFirst() && i <= cat.getLast());
}
}
class InstrumentCategory {
private final String name;
private final int first;
private final int last;
public InstrumentCategory(String name, int first, int last) {
this.name = name;
this.first = first;
this.last = last;
}
/**
* #return the name
*/
public String getName() {
return name;
}
/**
* #return the first
*/
public int getFirst() {
return first;
}
/**
* #return the last
*/
public int getLast() {
return last;
}
#Override
public String toString() {
return name;
}
}
Hello guys would someone please help me with my program? I have a JComboBox and it has several items inside it. What I want to happen is that whenever the user will click a certain item inside the combobox it should display its item quantity. For example, I clicked on PM1 twice it should display 2 in quantity, if i clicked on PM4 five times then it should display 5 in quantity. I have two classes involved in my program the and the codes are below. By the way I also want to display the quantities beside the item displayed in class CopyShowOrder. Any help will be extremely appreciated Thanks in advance and more power!
Codes of CopyShow:
import java.util.Scanner;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CopyShow{
private static String z = "";
private static String w = "";
private static String x = "";
JComboBox combo;
private static String a = "";
public CopyShow(){
String mgaPagkainTo[] = {"PM1 (Paa/ Spicy Paa with Thigh part)","PM2 (Pecho)","PM3 (Pork Barbeque 4 pcs.)","PM4 (Bangus Sisig)","PM5 (Pork Sisig)","PM6 (Bangus Inihaw)","SM1 (Paa)","SM2 (Pork Barbeque 2 pcs.)","Pancit Bihon","Dinuguan at Puto","Puto","Ensaladang Talong","Softdrinks","Iced Tea","Halo-Halo","Leche Flan","Turon Split"};
JFrame frame = new JFrame("Mang Inasal Ordering System");
JPanel panel = new JPanel();
combo = new JComboBox(mgaPagkainTo);
combo.setBackground(Color.gray);
combo.setForeground(Color.red);
panel.add(combo);
frame.add(panel);
combo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String str = (String)combo.getSelectedItem();
a = str;
CopyShowOrder messageOrder1 = new CopyShowOrder();
messageOrder1.ShowOrderPo();
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,250);
frame.setVisible(true);
}
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
boolean ulitinMoPows = true;
boolean tryAgain = true;
System.out.print("\nInput Customer Name: ");
String customerName = inp.nextLine();
w = customerName;
System.out.print("\nInput Cashier Name: ");
String user = inp.nextLine();
z = user;
do{
System.out.print("\nInput either Dine In or Take Out: ");
String dInDOut = inp.nextLine();
x = dInDOut;
if (x.equals("Dine In") || x.equals("Take Out")){
System.out.print("");
ulitinMoPows = false;
}
else{
JOptionPane.showMessageDialog(null, "Try again! Please input Dine In or Take Out only!","Error", JOptionPane.ERROR_MESSAGE);
ulitinMoPows = true;
System.out.print ("\f");
}
}while(ulitinMoPows);
do{
System.out.print("\nInput password: ");
String pass = inp.nextLine();
if(pass.equals("admin")){
CopyShowOrder messageShowMenu = new CopyShowOrder();
messageShowMenu.ShowMo();
tryAgain = false;
}
if(!pass.equals("admin")){
JOptionPane.showMessageDialog(null, "Try again! Invalid password!","Error Logging-In", JOptionPane.ERROR_MESSAGE);
tryAgain = true;
System.out.print ("\f");
}
}while(tryAgain);
CopyShow j = new CopyShow();
}
public static String kuhaOrder()
{
return a;
}
public static String kuhaUserName()
{
return z;
}
public static String kuhaCustomerName()
{
return w;
}
public static String kuhaSanKainPagkain()
{
return x;
}
}
Codes of CopyShowOrder:
public class CopyShowOrder {
public void ShowMo(){
String user = CopyShow.kuhaUserName();
System.out.print("\n\n\t\tCashier: " +user);
String dInDOut = CopyShow.kuhaSanKainPagkain();
System.out.print(" "+dInDOut);
String customerName = CopyShow.kuhaCustomerName();
System.out.print("\n\t\tCustomer Name: " +customerName);
}
public void ShowOrderPo() {
String order = CopyShow.kuhaOrder();
System.out.print("\t\t\t\t\n " +order);
}
}
I'm not sure if is that what you want, but here it goes..
You can have an idea..
import java.awt.BorderLayout;
public class StackOverflow extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTable table;
private JComboBox comboBox = new JComboBox();
private JButton button = new JButton("+");
private JButton button_1 = new JButton("-");
private JScrollPane scrollPane = new JScrollPane();
private List<String> list = new ArrayList<String>();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
StackOverflow dialog = new StackOverflow();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public StackOverflow() {
setTitle("StackOverflow");
setBounds(100, 100, 339, 228);
comboBox.setModel(new DefaultComboBoxModel(new String[] {"ITEM 1", "ITEM 2", "ITEM 3", "ITEM 4", "ITEM 5", "ITEM 6"}));
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
scrollPane.setBounds(10, 43, 303, 131);
contentPanel.add(scrollPane);
{
table = new JTable();
table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"Item", "Count"
}
));
scrollPane.setViewportView(table);
}
}
//Gets the table model and clear it
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setRowCount(0);
//Add comboBox items to table
for (int i = 0; i < comboBox.getItemCount(); i++)
model.addRow(new Object[] { comboBox.getItemAt(i) , 0 });
comboBox.setBounds(10, 12, 203, 20);
contentPanel.add(comboBox);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String selectedItem = (String) comboBox.getSelectedItem();
for (int i = 0; i < table.getRowCount(); i++) {
String tableItem = (String) table.getValueAt(i, 0);
int count = (Integer) table.getValueAt(i, 1)+1;
if (selectedItem.equals(tableItem)) {
table.setValueAt(count, i, 1);
}
}
}
});
button.setBounds(223, 11, 41, 23);
contentPanel.add(button);
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String selectedItem = (String) comboBox.getSelectedItem();
for (int i = 0; i < table.getRowCount(); i++) {
String tableItem = (String) table.getValueAt(i, 0);
int count = (Integer) table.getValueAt(i, 1)-1;
if (selectedItem.equals(tableItem)) {
table.setValueAt(count, i, 1);
}
}
}
});
button_1.setBounds(272, 11, 41, 23);
contentPanel.add(button_1);
}
}
I have a problem.
I have an element that would JPanel.
In this JPanel would be four JButtons and image.
This image is 'green LED lights' that would change depending on which JButton would be pressed.
It works very well.
But also I want the JComboBox to change this paramter.
And here's the problem.
Although the parameter (from 1 to 4) is changing,(this shows JLabel near LEDs),
but the picture (LED lights) do not want to change it to the right one.
screenshot
The program is divided into 3 classes.
MyFrame.class This main class.
public class MyFrame extends JFrame {
int ctrlTriggers = 1;
private JLabel label = new JLabel();
private Triggers triggers;
private String[] typeTrig = {"1", "2", "3", "4"};
public MyFrame() {
JFrame frame = new JFrame("JComboBox Problem");
frame.setBounds(50, 0, 800, 240);
frame.setLayout(new BorderLayout());
int tvalue = 1;
String tstr = Integer.toString(tvalue);
JPanel panelTrig = new JPanel(new BorderLayout());
label = new JLabel(tstr, 4);
panelTrig.add(label);
final JLabel et = label;
triggers = new Triggers(typeTrig, "trigger " + Integer.toString(1));
triggers.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
Triggers tr = (Triggers) e.getSource();
int vol;
vol = (int) tr.getValue();
et.setText(Integer.toString(vol));
}
});
panelTrig.add(triggers, BorderLayout.LINE_START);
// JCOMBOBOX
JPanel pCombo = new JPanel();
pCombo.setLayout(new FlowLayout());
Presets combo = new Presets();
combo.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
Presets presetcombo = (Presets) e.getSource();
int tval;
tval = (int) presetcombo.getValue(ctrlTriggers);
label.setText(Integer.toString(tval));
triggers.setValue(tval);
}
});
pCombo.add(combo, BorderLayout.CENTER);
frame.add(pCombo, BorderLayout.CENTER);
frame.add(panelTrig, BorderLayout.LINE_START);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.show();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MyFrame();
}
});
}
}
Triggers.class This class is JPanel where is 4 JButton and 'LED like image'
public class Triggers extends JPanel
implements ActionListener, ItemListener {
public Triggers(String s[], String name) {
JPanel panel = new JPanel(new BorderLayout());
this.value = Integer.parseInt(s[selected]);
for (int i = 0; i < s.length; i++) {
ImageIcon cup = new ImageIcon();
button[i] = new JButton(z[i], cup);
button[i].setPreferredSize(new Dimension(70, 25));
Font font = button[i].getFont();
button[i].setFont(new Font(font.getFontName(), font.getStyle(), 10));
button[i].setActionCommand(s[i]);
if (i == selected) {
button[i].setSelected(true);
} else {
button[i].setSelected(false);
}
}
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < s.length; i++) {
group.add(button[i]);
button[i].addActionListener(this);
button[i].addItemListener(this);
}
diody = new JLabel(createImageIcon("/resources/diody/"
+ this.value
+ ".png"));
diody.setPreferredSize(new Dimension(20, 100));
JPanel triggs = new JPanel(new FlowLayout());
triggs.setPreferredSize(new Dimension(80, 120));
for (int i = 0; i < s.length; i++) {
triggs.add(button[i]);
}
panel.add(triggs, BorderLayout.LINE_START);
panel.add(diody, BorderLayout.LINE_END);
add(panel);
}
public void actionPerformed(ActionEvent e) {
cmd = e.getActionCommand();
diody.setIcon(createImageIcon("/resources/diody/"
+ cmd
+ ".png"));
if (cmd.equals("1")) {
setValue(1);
} else if (cmd.equals("2")) {
setValue(2);
} else if (cmd.equals("3")) {
setValue(3);
} else if (cmd.equals("4")) {
setValue(4);
}
}
public static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = Triggers.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public int setController() {
return value;
}
public void setValue(int k) {
this.value = k;
cmd = Integer.toString(this.value);
repaint();
fireChangeEvent();
}
public int getValue() {
return this.value;
}
public void setSel(int k) {
selected = k;
repaint();
fireChangeEvent();
}
public void itemStateChanged(ItemEvent ie) {
String s = (String) ie.getItem();
}
public void addChangeListener(ChangeListener cl) {
listenerList.add(ChangeListener.class, cl);
}
public void removeChangeListener(ChangeListener cl) {
listenerList.remove(ChangeListener.class, cl);
}
protected void fireChangeEvent() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ChangeListener.class) {
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((ChangeListener) listeners[i + 1]).stateChanged(changeEvent);
}
}
}
private ChangeEvent changeEvent = null;
private EventListenerList listenerList = new EventListenerList();
private JLabel diody;
private int x = 1;
private int y = 4;
private JButton button[] = new JButton[y];
double border = 4;
double vborder = 1;
int controller[] = new int[4];
String z[] = {"1", "2", "3", "4"};
private int selected;
private int value;
private String cmd;
}
class Presets Here is JCombobox.
public class Presets extends JPanel
implements ActionListener {
private int value;
private int[] ctrlIdx = new int[27];
private int controller;
private ChangeEvent changeEvent = null;
private EventListenerList listenerList = new EventListenerList();
private JLabel label;
private String[][] presets = {
{"0", "3"},
{"1", "2"},
{"2", "3"},
{"3", "1"},
{"4", "4"},
{"5", "2"},};
String[] ctrlName = {"preset 1 (value 3)", "preset 2 (value 2)", "preset 3 (value 3)", "preset 4 (value 1)", "preset 5 (value 4)", "preset 5 (value 2)"};
public Presets() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setPreferredSize(new Dimension(600, 30));
JComboBox combolist = new JComboBox(ctrlName);
combolist.setSelectedIndex(2);
combolist.addActionListener(this);
combolist.setPreferredSize(new Dimension(300, 30));
label = new JLabel();
label.setFont(label.getFont().deriveFont(Font.ITALIC));
label.setHorizontalAlignment(JLabel.CENTER);
int indeks = combolist.getSelectedIndex();
updateLabel(ctrlName[combolist.getSelectedIndex()], indeks);
label.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
label.setPreferredSize(new Dimension(300, 30));
panel.add(combolist, "East");
add(panel);
setPreferredSize(new Dimension(600, 40));
}
public void setSelectedItem(int a) {
}
public void setValue(int c, int v) {
controller = c;
value = v;
ctrlIdx[controller] = value;
repaint();
fireChangeEvent();
}
public int getController() {
return controller;
}
public int getValue(int c) {
int w = (int) ctrlIdx[c];
return (int) w;
}
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox) e.getSource();
String pres = (String) cb.getSelectedItem();
int indeks = cb.getSelectedIndex();
updateLabel(pres, indeks);
for (int i = 0; i < ctrlName.length; i++) {
for (int j = 0; j < 2; j++) {
setValue(j, Integer.parseInt(presets[indeks][j]));
}
}
}
protected void updateLabel(String name, int ii) {
label.setToolTipText("A drawing of a " + name.toLowerCase());
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = Presets.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public void addChangeListener(ChangeListener cl) {
listenerList.add(ChangeListener.class, cl);
}
public void removeChangeListener(ChangeListener cl) {
listenerList.remove(ChangeListener.class, cl);
}
protected void fireChangeEvent() {
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ChangeListener.class) {
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((ChangeListener) listeners[i + 1]).stateChanged(changeEvent);
}
}
}
}
Could someone help me, what am I doing wrong?
Your image is only begin loaded in the actionPerformed method of your Triggers class, which means when you call setValue in response to the stateChanged event thrown by the Presets class, no new image is begin loaded.
Move your image loading logic so it is either in the setValue method or triggered by the setValue method
How can I register a custom data flavour, such that when I call
TransferHandler.TransferSupport.isDataFlavorSupported()
it returns true?
The flavour is initialised like so
private final DataFlavor localObjectFlavor = new ActivationDataFlavor(DataManagerTreeNode.class, DataFlavor.javaJVMLocalObjectMimeType, "DataManagerTreeNode flavour");
Many thanks
I saw only once times correct code for JTable and DnD, offical code by Oracle (former Sun)
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.io.*;
public class FillViewportHeightDemo extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private DefaultListModel model = new DefaultListModel();
private int count = 0;
private JTable table;
private JCheckBoxMenuItem fillBox;
private DefaultTableModel tableModel;
private static String getNextString(int count) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < 5; i++) {
buf.append(String.valueOf(count));
buf.append(",");
}
buf.deleteCharAt(buf.length() - 1); // remove last newline
return buf.toString();
}
private static DefaultTableModel getDefaultTableModel() {
String[] cols = {"Foo", "Toto", "Kala", "Pippo", "Boing"};
return new DefaultTableModel(null, cols);
}
public FillViewportHeightDemo() {
super("Empty Table DnD Demo");
tableModel = getDefaultTableModel();
table = new JTable(tableModel);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.setDropMode(DropMode.INSERT_ROWS);
table.setTransferHandler(new TransferHandler() {
private static final long serialVersionUID = 1L;
#Override
public boolean canImport(TransferSupport support) {
if (!support.isDrop()) { // for the demo, we'll only support drops (not clipboard paste)
return false;
}
if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { // we only import Strings
return false;
}
return true;
}
#Override
public boolean importData(TransferSupport support) { // if we can't handle the import, say so
if (!canImport(support)) {
return false;
}
JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();// fetch the drop location
int row = dl.getRow();
String data; // fetch the data and bail if this fails
try {
data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException e) {
return false;
} catch (IOException e) {
return false;
}
String[] rowData = data.split(",");
tableModel.insertRow(row, rowData);
Rectangle rect = table.getCellRect(row, 0, false);
if (rect != null) {
table.scrollRectToVisible(rect);
}
model.removeAllElements(); // demo stuff - remove for blog
model.insertElementAt(getNextString(count++), 0); // end demo stuff
return true;
}
});
JList dragFrom = new JList(model);
dragFrom.setFocusable(false);
dragFrom.setPrototypeCellValue(getNextString(100));
model.insertElementAt(getNextString(count++), 0);
dragFrom.setDragEnabled(true);
dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());
dragFrom.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent me) {
if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) {
String text = (String) model.getElementAt(0);
String[] rowData = text.split(",");
tableModel.insertRow(table.getRowCount(), rowData);
model.removeAllElements();
model.insertElementAt(getNextString(count++), 0);
}
}
});
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
JPanel wrap = new JPanel();
wrap.add(new JLabel("Drag from here:"));
wrap.add(dragFrom);
p.add(Box.createHorizontalStrut(4));
p.add(Box.createGlue());
p.add(wrap);
p.add(Box.createGlue());
p.add(Box.createHorizontalStrut(4));
getContentPane().add(p, BorderLayout.NORTH);
JScrollPane sp = new JScrollPane(table);
getContentPane().add(sp, BorderLayout.CENTER);
fillBox = new JCheckBoxMenuItem("Fill Viewport Height");
fillBox.addActionListener(this);
JMenuBar mb = new JMenuBar();
JMenu options = new JMenu("Options");
mb.add(options);
setJMenuBar(mb);
JMenuItem clear = new JMenuItem("Reset");
clear.addActionListener(this);
options.add(clear);
options.add(fillBox);
getContentPane().setPreferredSize(new Dimension(260, 180));
}
#Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == fillBox) {
table.setFillsViewportHeight(fillBox.isSelected());
} else {
tableModel.setRowCount(0);
count = 0;
model.removeAllElements();
model.insertElementAt(getNextString(count++), 0);
}
}
private static void createAndShowGUI() {//Create and set up the window.
FillViewportHeightDemo test = new FillViewportHeightDemo();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.pack(); //Display the window.
test.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}
I want to add JComboBox inside a JTable (3,3) on column 1. But in the column 1 , each row will have its own set of ComboBox element.
When I tried to use
table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox_Custom));
Each row is being set to same set of ComboBox Values.
But I want each row ComboBox has different items.
example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays Swing)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.table.*;
public class EachRowEditorExample extends JFrame {
private static final long serialVersionUID = 1L;
public EachRowEditorExample() {
super("EachRow Editor Example");
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
System.out.println(info.getName());
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
}
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{{"Name", "MyName"}, {"Gender", "Male"}, {"Color", "Fruit"}}, new Object[]{"Column1", "Column2"});
JTable table = new JTable(dm);
table.setRowHeight(20);
JComboBox comboBox = new JComboBox();
comboBox.addItem("Male");
comboBox.addItem("Female");
comboBox.addComponentListener(new ComponentAdapter() {
#Override
public void componentShown(ComponentEvent e) {
final JComponent c = (JComponent) e.getSource();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
c.requestFocus();
System.out.println(c);
if (c instanceof JComboBox) {
System.out.println("a");
}
}
});
}
});
JComboBox comboBox1 = new JComboBox();
comboBox1.addItem("Name");
comboBox1.addItem("MyName");
comboBox1.addComponentListener(new ComponentAdapter() {
#Override
public void componentShown(ComponentEvent e) {
final JComponent c = (JComponent) e.getSource();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
c.requestFocus();
System.out.println(c);
if (c instanceof JComboBox) {
System.out.println("a");
}
}
});
}
});
JComboBox comboBox2 = new JComboBox();
comboBox2.addItem("Banana");
comboBox2.addItem("Apple");
comboBox2.addComponentListener(new ComponentAdapter() {
#Override
public void componentShown(ComponentEvent e) {
final JComponent c = (JComponent) e.getSource();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
c.requestFocus();
System.out.println(c);
if (c instanceof JComboBox) {
System.out.println("a");
}
}
});
}
});
EachRowEditor rowEditor = new EachRowEditor(table);
rowEditor.setEditorAt(0, new DefaultCellEditor(comboBox1));
rowEditor.setEditorAt(1, new DefaultCellEditor(comboBox));
rowEditor.setEditorAt(2, new DefaultCellEditor(comboBox2));
table.getColumn("Column2").setCellEditor(rowEditor);
JScrollPane scroll = new JScrollPane(table);
getContentPane().add(scroll, BorderLayout.CENTER);
setPreferredSize(new Dimension(400, 120));
setLocation(150, 100);
pack();
setVisible(true);
}
public static void main(String[] args) {
EachRowEditorExample frame = new EachRowEditorExample();
frame.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
just add EachRowEditor Class
package com.atos.table.classes;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
public class PartCustomerWindow2 {
public static final Object[][] DATA = { { 1, 2,3, 4,false }, { 5, 6,7, 8 ,true},{ 9, 10,11, 12,true }, { 13, 14,15, 16,true } };
public static final String[] COL_NAMES = { "One", "Two", "Three", "Four",MyTableModel1.SELECT };
JButton but = new JButton("Add");
private JComboBox jcomboBox = null;
private JTextField jTextField = null;
static Object[][] rowData = null;
private JTable table=null;
static JFrame frame = null;
HashMap mp = null;
static int count = 0;
String content = null;
public JTextField getjTextField() {
if(jTextField == null)
{
jTextField = new FMORestrictedTextField(FMORestrictedTextField.JUST_ALPHANUMERIC, 8);
}
mp = new HashMap();
mp.put("arif",2);
mp.put("8",6);
mp.put("12",10);
mp.put("14",16);
mp.put("pk1",22);
mp.put("pk3",23);
jTextField.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
if(count == 0)
content = jTextField.getText();
// System.out.println(content);
if(mp.containsKey(content))
{
JFrame parent = new JFrame();
JOptionPane.showMessageDialog(parent, "Already Assigned");
}
}
});
return jTextField;
}
public void setjTextField(JTextField jTextField) {
this.jTextField = jTextField;
}
public JComboBox getJcomboBox() {
if(jcomboBox == null)
{
jcomboBox = new JComboBox();
}
return jcomboBox;
}
public void setJcomboBox(JComboBox jcomboBox) {
this.jcomboBox = jcomboBox;
}
private void createAndShowGui(PartCustomerWindow2 ob)
{
/*rowData = new Object[DATA.length][];
for (int i = 0; i < rowData.length; i++) {
rowData[i] = new Object[DATA[i].length + 1];
for (int j = 0; j < DATA[i].length; j++) {
rowData[i][j] = DATA[i][j];
}
rowData[i][DATA[i].length] = Boolean.TRUE;
if(i == 2 || i ==3)
rowData[i][DATA[i].length] = Boolean.FALSE;
}*/
MyTableModel3 tableModel = new MyTableModel3(DATA, COL_NAMES, "My Table", ob);
table = new JTable(tableModel);
//table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
/*table.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
table.getSelectionModel().clearSelection();
}
});*/
TableColumnModel cm = table.getColumnModel();
/*cm.getColumn(2).setCellEditor(new DefaultCellEditor(
new JComboBox(new DefaultComboBoxModel(new String[] {
"Yes",
"No",
"Maybe"
}))));*/
/* String ar1[]= {"aa","aaa","aaaa"};
ob.getJcomboBox().setModel(new DefaultComboBoxModel(ar1));*/
cm.getColumn(2).setCellEditor(new DefaultCellEditor(
ob.getJcomboBox()));
cm.getColumn(3).setCellEditor(new DefaultCellEditor(
ob.getjTextField()));
JScrollPane scrollPane = new JScrollPane();
/* scrollPane.add("Table",table);
scrollPane.add("Button",but);*/
JFrame frame2 = new JFrame();
/* jcomboBox.setPreferredSize(new Dimension(100,20));
textField.setPreferredSize(new Dimension(100,20));
jcomboBox.setEnabled(false);
textField.setEnabled(false);
*/
JScrollPane scrollPane2 = new JScrollPane(but);
but.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if(table.getCellEditor() != null)
table.getCellEditor().stopCellEditing();
// TODO Auto-generated method stub
String[][] ar = new String[table.getRowCount()][5];
for(int i =0;i<table.getRowCount();i++)
{
for(int j=0;j<5;j++)
{
DATA[i][j] = table.getValueAt(i,j);
}
System.out.print(table.getValueAt(i,0)+" ");
System.out.print(table.getValueAt(i,1)+" ");
System.out.print(table.getValueAt(i,2)+" ");
System.out.print(table.getValueAt(i,3)+" ");
System.out.println(table.getValueAt(i,4)+" ");
}
System.out.println("*******************");
/*
for(int i=0;i<DATA.length;i++)
{
System.out.print(DATA[i][0]);
System.out.print(DATA[i][1]);
System.out.print(DATA[i][2]);
System.out.print(DATA[i][3]);
boolean check =(Boolean) DATA[i][4];
System.out.println(check);
}*/
}});
frame = new JFrame("PartCustomerWindow2");
//
//JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(new JScrollPane(table), BorderLayout.NORTH);
contentPane.add(but);
//
//frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* frame.getContentPane().add(scrollPane2);
frame.getContentPane().add(scrollPane3);
frame.getContentPane().add(scrollPane4);*/
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
PartCustomerWindow2 ob = new PartCustomerWindow2();
ob.createAndShowGui(ob);
}
}
#SuppressWarnings("serial")
class MyTableModel3 extends DefaultTableModel {
public static final String SELECT = "select";
String tablename;
PartCustomerWindow2 ob = null;
public MyTableModel3(Object[][] rowData, Object[] columnNames, String tableName,PartCustomerWindow2 ob) {
super(rowData, columnNames);
this.tablename = tableName;
this.ob = ob;
}
#Override
public Class<?> getColumnClass(int columnIndex) {
if (getColumnName(columnIndex).equalsIgnoreCase(SELECT)) {
return Boolean.class;
}
else
return super.getColumnClass(columnIndex);
}
#Override
public boolean isCellEditable(int row, int col) {
JComboBox jb = ob.getJcomboBox();
JTextField jt = ob.getjTextField();
if(((Boolean) getValueAt(row, getColumnCount() - 1)).booleanValue())
{
// jb.setEnabled(false);
jb.removeAllItems();
// System.out.println(jb.getItemCount());
if(row == 0)
{
jb.addItem("arif");
jb.addItem("asif");
jb.addItem("ashik");
jb.addItem("farooq");
jb.addItem("adkh");
}
if(row > 0)
{
jb.addItem("kjhds");
jb.addItem("sdds");
jb.addItem("asdfsdk");
jb.addItem("sdfsdf");
jb.addItem("sdf");
}
/*HashMap mp = new HashMap();
mp.put("arif",2);
mp.put("8",6);
mp.put("12",10);
mp.put("14",16);
mp.put("pk1",22);
mp.put("pk3",23);
*/
/* if(col == 3){
if(mp.containsKey(jt.getText()))
{
System.out.println("Sorry..!! already assigned");
jt.setFocusable(true);
}
jt.setText("");
jt.setEnabled(false);
}*/
}
else
{
// jb.setEnabled(true);
//jt.setEnabled(true);
}
if (col == getColumnCount()-1 ) {
return true;
}
else{
if (getColumnName(4).equalsIgnoreCase(SELECT) && ((Boolean) getValueAt(row, getColumnCount() - 1)).booleanValue())
{
// jb.setEnabled(true);
// jt.setEnabled(true);
return (col == 2 || col == 3);
}
else{
// jb.setEnabled(false);
//jt.setEnabled(false);
return false;
}
}
}
}