2 Replies - 2421 Views - Last Post: 02 February 2010 - 09:10 AM Rate Topic: -----

#1 cotekyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-September 09

Adding a combobox to a tabbed pane

Posted 01 February 2010 - 09:05 AM

I am trying to add a combobox with some JLabels to one panel of a tabbed pane. The way I have tried doesn't work, nothing shows up in the panel, so I'm assuming it is a simple error I'm just passing over. Any help would be greatly appreciated. Here is the constructor the part in question is at the bottom:

public ColorPanel(){
		setTitle("Text Adventure!");
   		setSize(700,400);
   		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   		setLocationRelativeTo(null);
   		setResizable(true);
		setBackground(Color.BLACK);
		JMenuBar menuBar = new JMenuBar();
		
		JPanel s  = new JPanel();
		JScrollPane js1 = new JScrollPane(s);
		JPanel s2 = new JPanel();
		JScrollPane js2 = new JScrollPane(s2);
		
		setJMenuBar(menuBar);
		JMenu fileMenu = new JMenu("File");
		menuBar.add(fileMenu);
		JMenuItem saveAction = new JMenuItem("Save");
		JMenuItem exitAction = new JMenuItem("Exit");
		fileMenu.add(saveAction);
		fileMenu.addSeparator();
		fileMenu.add(exitAction);
		
		saveAction.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//save to text file?
			}
		});
		
		exitAction.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		
		classList = new JComboBox(classes);
		classList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enteredValues[0] = (String) classList.getSelectedItem();
		}
		});
		
		genderList = new JComboBox(genders);
		genderList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				enteredValues[1] = (String) genderList.getSelectedItem();
		}
		});
		
		classtype = new JLabel("Class");
		gender = new JLabel("Gender");
		comboPanel = new JPanel();
		labelPanel = new JPanel();
		
		JTabbedPane tabbedPane = new JTabbedPane();
		tabbedPane.addTab("Story", js1);
		tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
		tabbedPane.addTab("Character Attributes", js2);
		tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
		
		Container c = this.getContentPane();

				labelPanel.add(classtype);
		labelPanel.add(classList);
		
		labelPanel.add(gender);
		labelPanel.add(genderList);
		
		js2.add(comboPanel);
		js2.add(labelPanel);
		c.add(tabbedPane);
		
	}
}

This post has been edited by cotekyle: 01 February 2010 - 09:11 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Adding a combobox to a tabbed pane

#2 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2670
  • View blog
  • Posts: 15,716
  • Joined: 24-September 08

Re: Adding a combobox to a tabbed pane

Posted 01 February 2010 - 10:59 AM

One thing I am not getting... why are you adding a menu to a panel? Your way is kinda whacky. Look at this for reference... http://java.sun.com/...tabbedpane.html

Basically, create your panel, all its contents, add contents to panel, then add them to the pane. You add your menu bar to the main frame you're working with. Try extending the classes to make it neater. Hope that helped a little.

This post has been edited by NeoTifa: 01 February 2010 - 11:00 AM

Was This Post Helpful? 1
  • +
  • -

#3 cotekyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 11-September 09

Re: Adding a combobox to a tabbed pane

Posted 02 February 2010 - 09:10 AM

Thanks, that helped. :) My coding was really weird I just had to clean it up and rearrange some things and it works now.

BTW that link you posted doesn't work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1