1 Replies - 253 Views - Last Post: 06 October 2013 - 10:25 AM Rate Topic: -----

#1 Odko  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 25-October 12

How to use JList in GUI ?

Posted 06 October 2013 - 10:19 AM

Hi everyone! I have question regarding my homework. I wanted to do a desktop application for stock marketing. The app has 3 buttons which is choice 3 different stock markets, when I click the one button, it shows the lists of stocks. The my problem is how I place the lists under my the specific button. Actually, the list is placed bottom of buttons. Here I am going to summit some code. Please give me some hint and help.
I will truly appreciate :).

		JLabel lblWelcomeToStockin = new JLabel("Welcome to StockIn!");
		lblWelcomeToStockin.setBounds(332, 28, 150, 16);
		contentPane.add(lblWelcomeToStockin);
		
		JLabel lblNewLabel = new JLabel("Please select a Stock Market and");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(252, 89, 304, 16);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("a Stock Company you wish.");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel_1.setBounds(296, 129, 224, 16);
		contentPane.add(lblNewLabel_1);
		
		JTree tree_2 = new JTree();
		tree_2.setBackground(Color.WHITE);
		tree_2.setModel(new DefaultTreeModel(
			new DefaultMutableTreeNode("NASDAQ") {
				{
					DefaultMutableTreeNode node_1;
					node_1 = new DefaultMutableTreeNode("NASDAQ");
						node_1.add(new DefaultMutableTreeNode("blue"));
						node_1.add(new DefaultMutableTreeNode("violet"));
						node_1.add(new DefaultMutableTreeNode("red"));
						node_1.add(new DefaultMutableTreeNode("yellow"));
					add(node_1);
					node_1 = new DefaultMutableTreeNode("NASDAQ-100");
						node_1.add(new DefaultMutableTreeNode("basketball"));
						node_1.add(new DefaultMutableTreeNode("soccer"));
						node_1.add(new DefaultMutableTreeNode("football"));
						node_1.add(new DefaultMutableTreeNode("hockey"));
					add(node_1);
					node_1 = new DefaultMutableTreeNode("PRE MARKET");
						node_1.add(new DefaultMutableTreeNode("hot dogs"));
						node_1.add(new DefaultMutableTreeNode("pizza"));
						node_1.add(new DefaultMutableTreeNode("ravioli"));
						node_1.add(new DefaultMutableTreeNode("bananas"));
					add(node_1);
				}
			}
		));
		tree_2.setShowsRootHandles(true);
		tree_2.setBounds(0, 191, 165, 279);
		contentPane.add(tree_2);



Is This A Good Question/Topic? 0
  • +

Replies To: How to use JList in GUI ?

#2 ChrisNt  Icon User is offline

  • cute bug

Reputation: 225
  • View blog
  • Posts: 723
  • Joined: 31-July 13

Re: How to use JList in GUI ?

Posted 06 October 2013 - 10:25 AM

If i understand you need an ActionListener so when you press a JButton you can see the appropriate list of stock.Create an inner class which implements ActionListener and in the method actionPerformed(ActionEvent e ) which you override check which JButton was pressed and show the appropriate stock list.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1