Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2004

Tip: Looking for answers? Try searching our database.

setModel() and updateUI() ????

Thread view: 
jssim - 18 Feb 2004 14:08 GMT
hi~ all

one>
list.setModel(listModel);
list.updateUI();

two>
list.setModel(listModel);
//list.updateUI();

It makes a difference..

and I'm learning english and I'm not fluent in english..
but don't worry.. I'm great reading..^^

It makes a difference..
please tell me the reason..

thanks..

=================================================

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class DelegateEx extends JFrame implements ActionListener {

private JTextField tf = new JTextField();

private DelegateListModel listModel = new DelegateListModel();
private JList list = new JList();
private JScrollPane scroll = new JScrollPane(list);

public DelegateEx() {
super("UI-Model Ex");

JPanel cpPane = (JPanel)getContentPane();
cpPane.setLayout(new BorderLayout());
cpPane.add(tf, BorderLayout.NORTH);
cpPane.add(scroll, BorderLayout.CENTER);

tf.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == tf) {
String str = tf.getText();
if (str.length() < 0) return;

listModel.addRow(str);

///////////////////////////////
list.setModel(listModel);
list.updateUI();

///////////////////////////////

tf.select(0, str.length());
}
}

public static void main(String args[]) {
DelegateEx frm = new DelegateEx();
frm.setVisible(true);
frm.pack();
}
}

class DelegateListModel extends AbstractListModel {

private Vector listData = new Vector();

public Vector getListData() {
return listData;
}
public void addRow(String sItem) {
if (sItem == null) return;
listData.addElement(sItem);
}

public int getSize() {
return listData.size();
}
public Object getElementAt(int index) {
return listData.get(index);
}
}
Andrew Thompson - 18 Feb 2004 14:17 GMT
> hi~ all

hi~ one

> one>
> list.setModel(listModel);
[quoted text clipped - 5 lines]
>
> It makes a difference..

yeeees it does.  The second
one does not update the
user interface.   ;-)    (ducks)

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.