Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
JList values not appearing in the applet. I can see values in applet viewer. Two panels used.
Mona Salem
Greenhorn
Posts: 1
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.event.*; import javax.swing.*; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.LayoutManager; import java.awt.FlowLayout; import java.awt.Insets; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.util.ArrayList; public class QueryWindow extends JApplet{ JTextField textField; JButton button, button2; JLabel label, label2 ; JList listbox ; JPanel thePanel; JPanel Panel1, Panel2; DefaultListModel listModel; public void init(){ this.setSize(640,640); GridBagLayout layout =new GridBagLayout(); thePanel = new JPanel(); thePanel.setLayout(layout); GridBagConstraints gridConstraints = new GridBagConstraints(); //define the x,y positions of the components gridConstraints.gridx = 0; gridConstraints.gridy = 0; gridConstraints.gridwidth = 2; gridConstraints.gridheight = 1; gridConstraints.weightx = 10; gridConstraints.weighty = 10; gridConstraints.insets = new Insets(5,5,5,5); gridConstraints.anchor = GridBagConstraints.CENTER; gridConstraints.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(" ", 60); Font font =new Font("Helvetica", Font.PLAIN, 18); textField.setFont(font); button = new JButton("Enter Your Query"); label = new JLabel(" "); thePanel.add(textField, gridConstraints); gridConstraints.gridwidth = 1; gridConstraints.gridx = 62; thePanel.add(button, gridConstraints); gridConstraints.gridwidth = 1; gridConstraints.gridx = 1; gridConstraints.gridy = 2; thePanel.add(label, gridConstraints); gridConstraints.gridwidth = 3; gridConstraints.gridheight = 20; gridConstraints.gridx = 1; gridConstraints.gridy = 3; gridConstraints.fill = GridBagConstraints.BOTH; Panel2 = new JPanel((LayoutManager) new FlowLayout(FlowLayout.LEFT)); label2 = new JLabel("Annotations "); Panel2.add(label2); listModel = new DefaultListModel(); listbox = new JList(listModel); listbox.setVisibleRowCount(10); listbox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); Panel2.add(new JScrollPane(listbox)); thePanel.add(Panel2, gridConstraints); //create an object that will monitor the button click GetResultsListener butListener = new GetResultsListener(); button.addActionListener(butListener); this.add(thePanel); this.setVisible(true); } class GetResultsListener implements ActionListener{ public void actionPerformed(ActionEvent e) { String textFieldText = textField.getText(); ArrayList<String> A1 = new ArrayList<String>(); // Long string chopped up, and smaller strings placed in A1. I print out the values on my screen in applet viewer. They are there. AnnotateQuery annotateQuery =new AnnotateQuery(); try { annotateQuery.queryToAnnotate(textFieldText, A1); for (int h=0; h<A1.size(); h++) { listModel.addElement(A1.get(h)); } } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } thePanel.repaint(); // Panel2.revalidate(); Panel2.repaint(); } } } }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
GridBagLayout resize issue
Applet - Browser Display
GridBagLayout
Question about JPanel
Why are my JFrames closing?
More...