public void closeTab() {
        String name = this.name;

        if (!name.startsWith("#") && !name.equals(this.server)) //closing IM
        {
            GUI.getTabbedPane().remove(this);
        }

        if (name.startsWith("#")) //closing channel
        {
            try {
                this.connection.send("PART " + name+" :"+GUI.leaveMessage);
                return;
            } catch (IOException | BadLocationException ex) {
                Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (name.equals(this.server)) //closing server
        {
            if (this.connection.isConnected) {
                int warning = JOptionPane.showConfirmDialog(null, "Do you wish to disconnect from " + this.server + "? All tabs will be closed.", "Are you sure?", JOptionPane.WARNING_MESSAGE);
                if (warning == JOptionPane.CANCEL_OPTION || warning == JOptionPane.CLOSED_OPTION) return;
            }
            for (int i = 0; i < GUI.getTabbedPane().getTabCount(); i++) {
                ChannelPanel c = (ChannelPanel) GUI.getTabbedPane().getComponentAt(i);
                if (c.server.equals(this.server)) {
                    GUI.getTabbedPane().remove(i);
                    i--;
                }
            }
            GUI.getTabbedPane().remove(this);
            this.connection.disconnect();
            this.updateTabInfo();
        }
    }