Hello once again everyone. I would like to know if anyone could assist me on how to insert text from a JFormattedTextField and an item from a JComboBox and place them into a JTextPane. If the user enters an item name like Shoe in the JFormattedTextField and then selects an item number from a JComboBox then press an enter button, how can I allow both to be displayed in a JTextPane. I know how to do the tabs and alignments, just having a bit of difficulty in getting them to actually display in the JTextPane. I have an example of what my code looks like below. I left the cases blank because I'm not sure what I should place there at the moment. Thanks for taking the time to look at my code!

String[] clothNames = { "Hat", "Shoes", "Jeans", "Socks", "Shirt" };

JComboBox clothingBox = new JComboBox(clothNames);
JFormattedTextField itemNumber= new JFormattedTextField();
JTextPane clothingTextPane = new JTextPane();

 public JTextPane addTextToTextPane()
{
		 Document doc = clothingTextPane.getDocument();
		 try
		 {
			 doc.remove(0, doc.getLength());

			 for (int j = 0; j<clothNames.length; j++)
			 {
				 doc.insertString(doc.getLength(), clothNames[j] + "\t", clothingTextPane.getStyle("bold"));
			 }
		 }
		 catch(BadLocationException ble)
		 {
			 System.err.println("Couldn't insert text.");
		 }

		 return clothingTextPane;
}
public void actionPerformed(ActionEvent e)
{

		String arg = e.getActionCommand();

               if(arg == "Enter")
		{

					switch(clothingBox.getSelectedIndex())
					{
						case 0:
							break;
						case 1:
							break;
						case 2:
							break;
						case 3:
							break;
						case 4:
							break;
					}


		}
}

If you just need to get the text of the selected item from the combo box you can use getSelectedObject().

Thanks again Ezz. You've really helped me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.