public TabPane(){
		this.addChangeListener(new ChangeAdapter(){
			public void stateChanged(ChangeEvent e) {
				if(TabPane.this.getSelectedIndex() != -1){
					setFlash(false, TabPane.this.getSelectedIndex(), false);
				}
			}
		});
		this.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent event) {
				if(SwingUtilities.isRightMouseButton(event)){
					int index = TabPane.this.indexAtLocation(event.getX(), event.getY());
					Client.getChannel(TabPane.this.getTitleAt(index).replace("#", "")).leave(true, index);					
					
					// debug
					String t = "";
					for(Channel c : Client.getChannels()) t = t.concat(c.getName()+" ");
					Client.getLogger().debug("channels now contain: "+t);
					
					////////
					
				}else if(SwingUtilities.isLeftMouseButton(event)){
					int index = TabPane.this.indexAtLocation(event.getX(), event.getY());
					if(index >= 0){
						Client.getChannel(TabPane.this.getTitleAt(index).replace("#", "")).getTextField().requestFocusInWindow();
						Client.getGUI().getUserPane().expandChannel(TabPane.this.getTitleAt(index).replaceFirst("#", ""));
					}
				}
			}
			
			public void mouseReleased(MouseEvent e) {
				if(dragging) {
					int tabNumber = getUI().tabForCoordinate(TabPane.this, e.getX(), 10);

					if(tabNumber >= 0) {
						insertTab(title, null, component, null, tabNumber);
						TabPane.this.setSelectedIndex(tabNumber);
					}else{
						insertTab(title, null, component, null, TabPane.this.getTabCount());
						TabPane.this.setSelectedIndex(TabPane.this.getTabCount()-1);
					}

					Client.getGUI().getUserPane().orderNodes(getTabNames());
					Client.getGUI().getUserPane().expandChannel(title.replaceFirst("#", ""));
					Client.getRelayConfiguration().setDefaultChannels(Arrays.asList(getTabNames()));
					
					TabPane.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
				}

				dragging = false;
				tabImage = null;

			}

		});
		this.addMouseMotionListener(new MouseMotionAdapter(){

			public void mouseDragged(MouseEvent e) {
				if(!dragging) {
					// Gets the tab index based on the mouse position
					int tabNumber = getUI().tabForCoordinate(TabPane.this, e.getX(), e.getY());

					if(tabNumber >= 0) {
						draggedTabIndex = tabNumber;
						Rectangle bounds = getUI().getTabBounds(TabPane.this, tabNumber);

						// Paint the tabbed pane to a buffer
						Image totalImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
						Graphics totalGraphics = totalImage.getGraphics();
						totalGraphics.setClip(bounds);
						// Don't be double buffered when painting to a static image.
						setDoubleBuffered(false);
						paintComponent(totalGraphics);

						// Paint just the dragged tab to the buffer
						tabImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
						Graphics graphics = tabImage.getGraphics();
						graphics.drawImage(totalImage, 0, 0, bounds.width, bounds.height, bounds.x, bounds.y, bounds.x + bounds.width, bounds.y+bounds.height, TabPane.this);

						dragging = true;

						component = getComponentAt(draggedTabIndex);
						title = getTitleAt(draggedTabIndex);
						removeTabAt(draggedTabIndex);

						repaint();
					}
				} else {
					currentMouseLocation = e.getPoint();
					TabPane.this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

					repaint();
				}
				super.mouseDragged(e);
			}

		});

	}