I am creating a program to store Product information. Anyone know how to create auto fill function on java??
example:
when i fill productID, the product's name should be filled automatically >,<?
Anyone has solution ??
Question About Auto Fill
Page 1 of 15 Replies - 639 Views - Last Post: 08 April 2011 - 07:02 PM
Replies To: Question About Auto Fill
#2
Re: Question About Auto Fill
Posted 08 April 2011 - 05:11 AM
You more than likely would need some thread that automatically checks the current string in the textbox against the current products. That is a really interesting thing, i will look into it and see what i can come up with
#3
Re: Question About Auto Fill
Posted 08 April 2011 - 05:53 AM
This is a pretty cool thing, at the moment i have just setup a very basic and inefficient way of doing things. Basically i have added a KeyListener interface on the JTextField and each time an ActionEvent is fired i just iterate a list and update a JLabel containing a suggestion of what the word may be. It is very ghetto and i will look at implementing something better.
I will just put this out there until such time as i address it further. It works somewhat, however is far from complete or perfect. Should help you get started.
I will just put this out there until such time as i address it further. It works somewhat, however is far from complete or perfect. Should help you get started.
/**
*
* @author DaneAU
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Main extends JFrame implements ActionListener, KeyListener {
private LinkedList<String> words;
private JButton btnOk;
private JTextField txtInputField;
private JLabel lblOutput;
private Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new GridLayout(3,1,5,5));
setSize(200,100);
initComponents();
this.add(lblOutput);
this.add(txtInputField);
this.add(btnOk);
// Just add some words
words = new LinkedList<String>();
words.add("dream");
words.add("dreamincode");
words.add("in");
words.add("code");
words.add("isftw");
}
private void initComponents() {
btnOk = new JButton("OK");
btnOk.addActionListener(this);
txtInputField = new JTextField();
txtInputField.addActionListener(this);
txtInputField.addKeyListener(this);
lblOutput = new JLabel("Output Info");
}
public void actionPerformed(ActionEvent evt) {
if( evt.getSource() == btnOk ) {
}
if( evt.getSource() == txtInputField ) {
lblOutput.setText( txtInputField.getText());
}
}
public void keyPressed(KeyEvent evt) {
if(evt.getSource() == txtInputField) {
String suggestion = "unknown word";
String current = txtInputField.getText();
for( String s : words ) {
if( s.contains(current.subSequence(0, current.length()))) {
suggestion = "perhaps : " + s;
break;
}
}
lblOutput.setText(suggestion);
}
}
public void keyReleased(KeyEvent evt) {
}
public void keyTyped(KeyEvent evt) {
}
public static void main(String[] args) {
Main myApp = new Main();
myApp.setVisible(true);
}
}
#4
Re: Question About Auto Fill
Posted 08 April 2011 - 09:51 AM
Wow Awesome Job
, i was thinking about key binding..it still inefficient to use.
thanks for the answer
thanks for the answer
#5
Re: Question About Auto Fill
Posted 08 April 2011 - 06:58 PM
DaneAU, on 08 April 2011 - 07:11 AM, said:
You more than likely would need some thread that automatically checks the current string in the textbox against the current products. That is a really interesting thing, i will look into it and see what i can come up with 
Yash... what an horrible solution. There are better ways of doing that
#6
Re: Question About Auto Fill
Posted 08 April 2011 - 07:02 PM
Yea i have come to realise that there are better ways indeed. It would be a pretty handy thing for my current application, so i will put up a snippet once i get it working right
Don't use a thread or you could run into problems.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|