
com.viaoa.jfc.text.view.OpenList Maven / Gradle / Ivy
/* Copyright 1999-2015 Vince Via [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.viaoa.jfc.text.view;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
import javax.swing.event.*;
public class OpenList extends JPanel implements ListSelectionListener, ActionListener {
protected JLabel m_title;
protected JTextField m_text;
protected JList m_list;
protected JScrollPane m_scroll;
public OpenList(int[] data, String title) {
setLayout(null);
m_title = new JLabel(title, JLabel.LEFT);
add(m_title);
m_text = new JTextField();
m_text.addActionListener(this);
add(m_text);
String[] ss = new String[data.length];
for (int i=0; i 0)
m_list.setSelectedIndex(0);
}
public int getSelectedIndex() {
return m_list.getSelectedIndex();
}
public void setSelected(String sel) {
m_list.setSelectedValue(sel, true);
m_text.setText(sel);
}
public String getSelected() { return m_text.getText(); }
public void setSelectedInt(int value) {
setSelected(Integer.toString(value));
}
public int getSelectedInt() {
try {
return Integer.parseInt(getSelected());
}
catch (NumberFormatException ex) { return -1; }
}
public void valueChanged(ListSelectionEvent e) {
Object obj = m_list.getSelectedValue();
if (obj != null)
m_text.setText(obj.toString());
}
public void actionPerformed(ActionEvent e) {
ListModel model = m_list.getModel();
String key = m_text.getText().toLowerCase();
for (int k=0; k
© 2015 - 2025 Weber Informatics LLC | Privacy Policy