Tabbed pane again.............important

My kod looks like this:
tabbedPane.addTab("Schema",null,new test(), "testing");
This part lies in a .java file and test lies in a fiel called test.java. I am having ig problems getting the tab to open this fiel when i click on it. Could i pleas get some help

Why are you starting a new thread to ask the same question? You where given the answer in your other thread:
http://forum.java.sun.com/thread.jsp?forum=57&thread=503438
The answer was: "Implement a ChangeListener"
If your new question is "How do I implement a Change Listener" then read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/events/changelistener.html]How to Write a Change Listener".

Similar Messages

  • How can i place button on top right hand corner of the tabbed pane

    Hi all,
    i want to place button on top right hand corner of the tabbed pane, just run the code below, i have add button(it going to insert tab into tabbedpane), i want to place that tab into top right hand corner of the tabbedpane (not inside the tab itself). if i set tab policy setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT), it will give two button at right hand corner along with those buttons i want to and one more add button.
    please suggest so that i can move forward.
    Thanks in advance
    import java.awt.Dimension;
    import java.util.HashMap;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    * @author  Dayananda.BV
    public class TabpaneDemo extends javax.swing.JFrame {
        /** Creates new form TabpaneDemo */
        HashMap<Integer, tabpanel> panelMap = new HashMap<Integer, tabpanel>();
        public TabpaneDemo() {
            initComponents();
            createFloorPlan();
            getContentPane().setPreferredSize(new Dimension(400,400));
            jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jTabbedPane1 = new javax.swing.JTabbedPane();
            add_tab_button = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            add_tab_button.setText("+");
            add_tab_button.setMargin(new java.awt.Insets(0, 0, 0, 0));
            add_tab_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    add_tab_buttonActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(308, Short.MAX_VALUE)
                    .addComponent(add_tab_button, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(67, 67, 67))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(add_tab_button)
                    .addGap(8, 8, 8)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void createFloorPlan(){
            tabpanel floorplan_Panel = new tabpanel(panelMap.size()+1);
            panelMap.put(floorplan_Panel.getTabIndex(), floorplan_Panel);
            jTabbedPane1.add(floorplan_Panel, floorplan_Panel.getTabName());
            jTabbedPane1.setSelectedIndex(jTabbedPane1.getTabCount()-1);
        private void add_tab_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                              
            createFloorPlan();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TabpaneDemo().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JButton add_tab_button;
        private javax.swing.JTabbedPane jTabbedPane1;
        // End of variables declaration                  
        class tabpanel extends JPanel{
            private int tabIndex = 0;
            private String tabName ;
            public tabpanel(int tabIndex) {
                this.tabIndex = tabIndex;
                if(tabIndex >= 10) {
                    tabName = "Floor Map"+tabIndex;
                } else{
                    tabName = "Floor Map"+tabIndex+"  ";
            public int getTabIndex(){
                return tabIndex;
            public String getTabName(){
                return tabName;
    }Thanks
    Dayananda B V

    This part of tabbed pane is not customizable as it lies in the ComponentUI(TabbedpaneUI) portion of the tabbedpane.
    But I can point out the place u can change to bring the desired feature into effect.
    U can find an Inner class called ScrollableTabSupport
    Look for the methods createButtons where u can create extra buttons and add to the tabbed pane.
    The Inner class also implements actionListener where u can implement the action for the button u added.
    By this method U have to use your own extended TabbedPaneUI which u cant escape from.
    Hope this will help u.

  • How to a particular panel in a tabbed pane to the front?

    Hello
    I have a small application that uses a tabbed pane. At some point I want to press a button in one of the panels of the tabbed pane and then another panel in the same tabbed pane to show up, as if I had clicked on that tab to bring it to the front.
    Only difference is I don't want to click on the tab to do it but on another button, so I can do some more stuff through the button before I bring the other panel to the front
    I thought I could do this by getting focus, but it seems not to be the case. Getting focus does not mean coming to the front as I originally thought.
    I hope this is clear. Here is an example that you can compile and run. I want to get jpanel2 to the front by clicking jbutton1 and vice versa.
    Any help appreciated.
    (Frame1.java)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Frame1 extends JFrame {
        private JTabbedPane jTabbedPane1 = new JTabbedPane();
        private JPanel jPanel1 = new JPanel();
        private JPanel jPanel2 = new JPanel();
        private JButton jButton1 = new JButton();
        private JButton jButton2 = new JButton();
        private JTextField jTextField1 = new JTextField();
        private JTextField jTextField2 = new JTextField();
        public Frame1() {
            try {
                jbInit();
                this.setDefaultCloseOperation(EXIT_ON_CLOSE);
                setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
        private void jbInit() throws Exception {
            this.getContentPane().setLayout( null );
            this.setSize( new Dimension(400, 300) );
            jTabbedPane1.setBounds(new Rectangle(0, 0, 395, 270));
            jPanel1.setLayout(null);
            jPanel2.setLayout(null);
            jButton1.setText("jButton1");
            jButton1.setBounds(new Rectangle(20, 170, 160, 25));
            jButton1.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            jButton1_actionPerformed(e);
            jButton2.setText("jButton2");
            jButton2.setBounds(new Rectangle(20, 135, 160, 25));
            jButton2.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            jButton2_actionPerformed(e);
            jTextField1.setBounds(new Rectangle(55, 45, 210, 20));
            jTextField2.setBounds(new Rectangle(95, 50, 180, 20));
            jPanel1.add(jTextField1, null);
            jPanel1.add(jButton1, null);
            jTabbedPane1.addTab("jPanel1", jPanel1);
            jPanel2.add(jTextField2, null);
            jPanel2.add(jButton2, null);
            jTabbedPane1.addTab("jPanel2", jPanel2);
            this.getContentPane().add(jTabbedPane1, null);
        private void jButton1_actionPerformed(ActionEvent e) {
        private void jButton2_actionPerformed(ActionEvent e) {
        public static void main(String[] args) {
            new Frame1();
    }

    tabbedPane.setSelectedIndex(...);

  • How to drag and drop tab nodes between tab panes

    I'm working on example from this tutorial( Drag-and-Drop Feature in JavaFX Applications | JavaFX 2 Tutorials and Documentation ). Based on the tutorial I want to drag tabs between two tabs. So far I managed to create this code but I need some help in order to finish the code.
    Source
    tabPane = new TabPane();
    Tab tabA = new Tab();
       Label tabALabel = new Label("Main Component");
    tabPane.setOnDragDetected(new EventHandler<MouseEvent>()
                @Override
                public void handle(MouseEvent event)
                    /* drag was detected, start drag-and-drop gesture*/
                    System.out.println("onDragDetected");
                    /* allow any transfer mode */
                    Dragboard db = tabPane.startDragAndDrop(TransferMode.ANY);
                    /* put a string on dragboard */
                    ClipboardContent content = new ClipboardContent();
                    content.put(DataFormat.PLAIN_TEXT, tabPane);
                    db.setContent(content);
                    event.consume();
    What is the proper way to insert the content of the tab as object? Into the tutorial simple text is transferred. How I must modify this line content.put(DataFormat.PLAIN_TEXT, tabPane);?
    And what is the proper way to insert the tab after I drag the tab:
    Destination
    tabPane.setOnDragDropped(new EventHandler<DragEvent>()
                @Override
                public void handle(DragEvent event)
                    /* data dropped */
                    /* if there is a string data on dragboard, read it and use it */
                    Dragboard db = event.getDragboard();
                    boolean success = false;
                    if (db.hasString())
                        //tabPane.setText(db.getString());
                        Tab tabC = new Tab();
                        tabPane.getTabs().add(tabC);
                        success = true;
                    /* let the source know whether the string was successfully
                     * transferred and used */
                    event.setDropCompleted(success);
                    event.consume();
    I suppose that this transfer can be accomplished?
    Ref javafx 2 - How to drag and drop tab nodes between tab panes - Stack Overflow

    I would use a graphic (instead of text) for the Tabs and call setOnDragDetected on that graphic. That way you know which tab is being dragged. There's no nice way to put the Tab itself into the dragboard as it's not serializable (see https://javafx-jira.kenai.com/browse/RT-29082), so you probably just want to store the tab currently being dragged in a property.
    Here's a quick example; it just adds the tab to the end of the current tabs in the dropped pane. If you wanted to insert it into the nearest location to the actual drop you could probably iterate through the tabs and figure the coordinates of each tab's graphic, or something.
    import java.util.Random;
    import javafx.application.Application;
    import javafx.beans.property.ObjectProperty;
    import javafx.beans.property.SimpleObjectProperty;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.Tab;
    import javafx.scene.control.TabPane;
    import javafx.scene.input.ClipboardContent;
    import javafx.scene.input.DragEvent;
    import javafx.scene.input.Dragboard;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.TransferMode;
    import javafx.scene.layout.StackPane;
    import javafx.scene.layout.VBox;
    import javafx.stage.Stage;
    public class DraggingTabPane extends Application {
      private static final String TAB_DRAG_KEY = "tab" ;
      private ObjectProperty<Tab> draggingTab ;
    @Override
      public void start(Stage primaryStage) {
      draggingTab = new SimpleObjectProperty<>();
      TabPane tabPane1 = createTabPane();
      TabPane tabPane2 = createTabPane();
      VBox root = new VBox(10);
      root.getChildren().addAll(tabPane1, tabPane2);
      final Random rng = new Random();
      for (int i=1; i<=8; i++) {
        final Tab tab = createTab("Tab "+i);
        final StackPane pane = new StackPane();
          int red = rng.nextInt(256);
          int green = rng.nextInt(256);
          int blue = rng.nextInt(256);
        String style = String.format("-fx-background-color: rgb(%d, %d, %d);", red, green, blue);
        pane.setStyle(style);
        final Label label = new Label("This is tab "+i);
        label.setStyle(String.format("-fx-text-fill: rgb(%d, %d, %d);", 256-red, 256-green, 256-blue));
        pane.getChildren().add(label);
        pane.setMinWidth(600);
        pane.setMinHeight(250);
        tab.setContent(pane);
        if (i<=4) {
          tabPane1.getTabs().add(tab);
        } else {
          tabPane2.getTabs().add(tab);
      primaryStage.setScene(new Scene(root, 600, 600));
      primaryStage.show();
      public static void main(String[] args) {
      launch(args);
      private TabPane createTabPane() {
        final TabPane tabPane = new TabPane();
        tabPane.setOnDragOver(new EventHandler<DragEvent>() {
          @Override
          public void handle(DragEvent event) {
            final Dragboard dragboard = event.getDragboard();
            if (dragboard.hasString()
                && TAB_DRAG_KEY.equals(dragboard.getString())
                && draggingTab.get() != null
                && draggingTab.get().getTabPane() != tabPane) {
              event.acceptTransferModes(TransferMode.MOVE);
              event.consume();
        tabPane.setOnDragDropped(new EventHandler<DragEvent>() {
          @Override
          public void handle(DragEvent event) {
            final Dragboard dragboard = event.getDragboard();
            if (dragboard.hasString()
                && TAB_DRAG_KEY.equals(dragboard.getString())
                && draggingTab.get() != null
                && draggingTab.get().getTabPane() != tabPane) {
              final Tab tab = draggingTab.get();
              tab.getTabPane().getTabs().remove(tab);
              tabPane.getTabs().add(tab);
              event.setDropCompleted(true);
              draggingTab.set(null);
              event.consume();
        return tabPane ;
      private Tab createTab(String text) {
        final Tab tab = new Tab();
        final Label label = new Label(text);
        tab.setGraphic(label);
        label.setOnDragDetected(new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            Dragboard dragboard = label.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent clipboardContent = new ClipboardContent();
            clipboardContent.putString(TAB_DRAG_KEY);
            dragboard.setContent(clipboardContent);
            draggingTab.set(tab);
            event.consume();
        return tab ;

  • Disposable tabbed pane redrawing

    Hi, i'm using disposable tabbed panes (with close button) in my program and i'm using following method to update their titles according to what user entered:
    //this is class extending JPanel
    public void updatePanelTitle(String newTitle) {
            MainPanel panel = (MainPanel) getParent(); //MainPanel extends JTabbedPane
            panel.setTitleAt(panel.getComponentZOrder(this)-1, newTitle);
            repaint();
        }Point is the title gets changed but the size of panel label does not. However, when i mouse-over the close button there, it gets changed to the size of the text.
    @Override
            public void mouseEntered(MouseEvent e) {
                Component component = e.getComponent();
                if (component instanceof AbstractButton) {
                    AbstractButton button = (AbstractButton) component;
                    button.setBorderPainted(true);
            }setBorderPainted calls inside the repaint method.
    Can anyone give a clue why it is not working or how to fix it?
    Regards,
    Marek

    Well its quite big but if it helps, this is the panel class:
    package presentationTier.view;
    import com.bbgroup.ui.Console;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.border.Border;
    import javax.swing.text.BadLocationException;
    import presentationTier.Model.Properties;
    import presentationTier.Model.PropertyInterface;
    import presentationTier.Model.StandardInputOutput;
    import presentationTier.controller.ConfirmListGeneratorAction;
    import presentationTier.controller.ConfirmSearchReplaceAction;
    import presentationTier.controller.OpenBrowseDialogAction;
    * @author marek
    public class ListGeneratorPanel extends JPanel implements StandardInputOutput, PropertyInterface {
        private JLabel labStartPath,  labExtensions;
        private JTextField txtStartPath,  txtExtensions;
        private JButton butBrowse,  butGo;
        private Console console;
        private GridBagConstraints c;
        private Insets labelInsets,  normalInsets;
        public ListGeneratorPanel() {
            super(new GridBagLayout());
            initComponents();
            borderCompononets(BorderFactory.createLoweredBevelBorder());
            resetConstraints();
            c.gridx = 0;
            c.gridy = 0;
            c.insets = labelInsets;
            add(labStartPath, c);
            c.gridx = 1;
            //c.gridwidth = 1;
            c.weightx = 1;
            c.insets = normalInsets;
            add(txtStartPath, c);
            c.gridx = 2;
            //c.gridwidth = 1;
            c.weightx = 0;
            add(butBrowse, c);
            c.gridx = 0;
            c.gridy = 1;
            c.weightx = 0;
            c.insets = labelInsets;
            add(labExtensions, c);
            c.gridx = 1;
            //c.gridwidth = 3;
            c.weightx = 1;
            c.insets = normalInsets;
            add(txtExtensions, c);
            c.gridx = 2;
            c.gridwidth = 1;
            //c.gridheight = 1;
            c.weightx = 0;
            add(butGo, c);
            c.gridx = 0;
            c.gridy = 2;
            c.gridwidth = 5;
            c.weighty = 1;
            add(new JScrollPane(console), c);
            resetConstraints();
        private void initComponents() {
            c = new GridBagConstraints();
            console = new Console(true);
            labelInsets = new Insets(5, 5, 0, 0);
            normalInsets = new Insets(5, 5, 0, 5);
            labStartPath = new JLabel("Search under:");
            labExtensions = new JLabel("File types:");
            txtStartPath = new JTextField();
            txtExtensions = new JTextField();
            butBrowse = new JButton(new OpenBrowseDialogAction(this));
            butGo = new JButton(new ConfirmListGeneratorAction(this));
        private void borderCompononets(Border b) {
            getTxtStartPath().setBorder(b);
            getTxtExtensions().setBorder(b);
        private void resetConstraints() {
            c.ipadx = 0;
            c.ipady = 0;
            c.gridwidth = 1;
            c.gridheight = 1;
            c.weightx = 0;
            c.weighty = 0;
            c.fill = GridBagConstraints.BOTH;
            c.anchor = GridBagConstraints.FIRST_LINE_START;
            c.insets = normalInsets;
        public Properties createProperties() {
            Properties p = new Properties();
            p.setSout(this);
            p.setStartPath(getTxtStartPath().getText());
            p.setExtensions(getTxtExtensions().getText());
            return p;
         * @param line
         * @throws BadLocationException
        public void echo(String line) throws BadLocationException {
            getConsole().echo(line);
         * @param line
         * @param style
         * @throws BadLocationException
        public void echo(String line, String style) throws BadLocationException {
            getConsole().echo(line, style);
        public void drawSeparator() throws BadLocationException {
            getConsole().drawSeparator();
        public void passBrowsedFilePath(String browsedFilePath) {
            getTxtStartPath().setText(browsedFilePath);
        public void updatePanelTitle(String newTitle) {
            MainPanel panel = (MainPanel) getParent();
            panel.setTitleAt(panel.getComponentZOrder(this) - 1, "Generate: " + newTitle);
            updateUI();
            repaint();
        public Console getConsole() {
            return console;
        public JTextField getTxtStartPath() {
            return txtStartPath;
        public JTextField getTxtExtensions() {
            return txtExtensions;
    }When you add instance of this to your JTabbedPane, you will get closeable Tabbed Pane with title you specified in addTab(title, component);
    I implement method updatePanelTitle(String newTitle); to change the title of this tab when suer submits the data. These action controllers that call submitting and updating title are in controller package. Problem is that the title itself is changed when data are submitted but the <b>size of the tab is not adjusted to newTitles length.</b> It is just adjusted when i pull my mouse over the close button that implements action from previous post. It's in this class:
    package com.bbgroup.ui;
    import javax.swing.*;
    import javax.swing.plaf.basic.BasicButtonUI;
    import java.awt.*;
    import java.awt.event.*;
    * Component to be used as tabComponent;
    * Contains a JLabel to show the text and
    * a JButton to close the tab it belongs to
    public class DisposableTabPanel extends JPanel {
        private final JTabbedPane pane;
        public DisposableTabPanel(final JTabbedPane pane) {
            //unset default FlowLayout' gaps
            super(new FlowLayout(FlowLayout.LEFT, 0, 0));
            if (pane == null) {
                throw new NullPointerException("TabbedPane is null");
            this.pane = pane;
            setOpaque(false);
            //make JLabel read titles from JTabbedPane
            JLabel label = new JLabel() {
                @Override
                public String getText() {
                    int i = pane.indexOfTabComponent(DisposableTabPanel.this);
                    if (i != -1) {
                        return pane.getTitleAt(i);
                    return null;
            add(label);
            //add more space between the label and the button
            label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
            //tab button
            JButton button = new TabButton();
            add(button);
            //add more space to the top of the component
            setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
        private class TabButton extends JButton implements ActionListener {
            public TabButton() {
                int size = 17;
                setPreferredSize(new Dimension(size, size));
                setToolTipText("Close this tab");
                //Make the button looks the same for all Laf's
                setUI(new BasicButtonUI());
                //Make it transparent
                setContentAreaFilled(false);
                //No need to be focusable
                setFocusable(false);
                setBorder(BorderFactory.createEtchedBorder());
                setBorderPainted(false);
                //Making nice rollover effect
                //we use the same listener for all buttons
                addMouseListener(buttonMouseListener);
                setRolloverEnabled(true);
                //Close the proper tab by clicking the button
                addActionListener(this);
            public void actionPerformed(ActionEvent e) {
                int i = pane.indexOfTabComponent(DisposableTabPanel.this);
                if (i != -1) {
                    pane.remove(i);
            //we don't want to update UI for this button
            public void updateUI() {
            //paint the cross
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g.create();
                //shift the image for pressed buttons
                if (getModel().isPressed()) {
                    g2.translate(1, 1);
                g2.setStroke(new BasicStroke(2));
                g2.setColor(Color.BLACK);
                if (getModel().isRollover()) {
                    g2.setColor(Color.MAGENTA);
                int delta = 6;
                g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
                g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
                g2.dispose();
        private final static MouseListener buttonMouseListener = new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                Component component = e.getComponent();
                if (component instanceof AbstractButton) {
                    AbstractButton button = (AbstractButton) component;
                    button.setBorderPainted(true);
            @Override
            public void mouseExited(MouseEvent e) {
                Component component = e.getComponent();
                if (component instanceof AbstractButton) {
                    AbstractButton button = (AbstractButton) component;
                    button.setBorderPainted(false);
    }I cant possibly post a running code as it uses third party libraries and implements bunch of interfaces, it would require whole nearly whole view-controller part of the project.
    Another problem is that method getComponentZOrder(this) - 1, works for retrieving all tabs except the first one (it returns fine indexes for any tab but -1 for the first one) but sadly there is no such method like getIndex(Component) which would be useful for getting <b>this</b> components index.
    Thanks in advance for ideas.
    Regards, Marek

  • How do you undo pane tiling?  Or get back to a tabbed pane?

    One of our developers has managed to 'untab' 3 sql panes so they are appearing as 3 separate dockable panes. How do you take these 3 panes back into a tabbed pane (other than restarting SQL Developer)?
    Message was edited by:
    Andy Riley

    A "hidden" feature that not many people discover is that you can double click on the tab for a code editor, and it will maximize to take the whole of the main window. Double click its tab again, and it will shrink back to its original size.
    Not exactly "tear-out" (which I agree would be nice... you should file that on the SQL Developer suggestion forum so that it winds its way back to the IDE team), but very useful if you have lots of code to edit :)
    Brian

  • Help with tabbed pane

    hello!
    i have a tabbed pane with two tabs.
    in tab1 i have a button(for example), how can i do that when i press the button in tab1 it will draw something in tab2?
    i tried to do this but it draw what i want in tab1(the tab with the button)
    if the source code will help i will post it here
    sorry for my bad english

    here's something to play around with
    (I've simplified it by putting it all in paintComponent, but it should be changed
    to get the image, if not null then repaint)
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    class Testing extends JFrame
      JTabbedPane tp = new JTabbedPane();
      JPanel p1 = new JPanel();
      MyJPanel p2 = new MyJPanel();
      public Testing()
        setSize(400,400);
        setLocation(300,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JButton btn = new JButton("Set image");
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            p2.imageFile = "Test.gif";
            p2.repaint();}});
        p1.add(btn);
        tp.addTab("Tab 1",p1);
        tp.addTab("Tab 2",p2);
        getContentPane().add(tp);
      public static void main(String[] args){new Testing().setVisible(true);}
    class MyJPanel extends JPanel
      String imageFile = null;
      public void paintComponent(Graphics g)
        super.paintComponent(g);
        if(imageFile != null)
          try
            URL url = new URL(getClass().getResource(imageFile), imageFile);
            Image img = ImageIO.read(url);
            g.drawImage(img, 50,50,this);
          catch(Exception e){JOptionPane.showMessageDialog(null,"Image error");}
    }

  • How to refrash tabbed pane at a run time

    hi,
    I have no practice in using tabbed panes, and now I have to solve a little problem. I am running internal frame wich contains tabbedpane. The tab which opens by default contains combobox which reads its data from DB. But when I open internal frame no data exists in a combobox.
    Since I change the tab and select back again the same tab data combobox reads its data. I tried to validate the tab but nothing changes.
    Where is my fault?

    The code that loads the data into the combo box is not being executed when you first create the internal frame. We can't tell you why since we have no idea what your code looks like.
    So, trace the order of execution to see why the code is not executing.

  • How to paste an image upper the tabbed pane

    Hello! I have a problem , i want to set the image in the following program at the top
    . Can i set the location of the tabbed pane?? and how?
    import javax.swing.JTabbedPane;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import java.awt.*;
    import java.awt.event.*;
    public class AdminPane extends JPanel {     
    public AdminPane()
    ImageIcon icon = new ImageIcon("images/green_phone.gif");
              JTabbedPane tabbedPane = new JTabbedPane();
              Component pane1 = makeTextPanel("Index Page");
    tabbedPane.addTab("Home", icon, pane1, "Index Page");
    tabbedPane.setSelectedIndex(0);
              Component pane2 = makeTextPanel("Debit Card Tables");
    tabbedPane.addTab("Debit Card System", icon, pane2, "Does twice as much nothing");
    Component pane3 = makeTextPanel("Merchant Tables");
    tabbedPane.addTab("Merchant System", icon, pane3, "Still does nothing");
    Component pane4 = makeTextPanel("Administrative Tools");
    tabbedPane.addTab("Administrative Tools", icon, pane4, "Does nothing at all");
    Component pane5 = makeTextPanel("Database Recure");
    tabbedPane.addTab("Database Recure", icon, pane5, "Does nothing at all");
              //Add the tabbed pane to this panel.
    setLayout(new GridLayout(2, 0));
              tabbedPane.setBackground(new Color(255, 255, 255));
              add(tabbedPane);
    // acquire the image
    image = Toolkit.getDefaultToolkit().getImage
    ("images/green_phone.gif");
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    try { tracker.waitForID(0); }
    catch (InterruptedException exception) {}
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    g.drawImage(image, 0, 300, null);
    private Image image;
    protected Component makeTextPanel(String text)
    JPanel panel = new JPanel(false);
    JLabel filler = new JLabel(text);
    filler.setHorizontalAlignment(JLabel.CENTER);
              //panel.setBackground(new Color(255, 255, 255));
    panel.setLayout(new GridLayout(1, 1));
              panel.add(filler);
    return panel;
    public static void main(String[] args)
    JFrame frame = new JFrame("AdminPane");
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e) {System.exit(0);}
    frame.getContentPane().add(new AdminPane(),
    BorderLayout.CENTER);
    frame.setSize(500, 550);
    frame.setVisible(true);

    Image at the top? Are you talking about the application image? Try setIconImage.
    To set the location of the tabbed pane, either use setLocation(...) or use some sort of layout manager
    to set the location of the Image relative to the tabbed pane, do
    Point p = tabbedpane.getLocation();
    Image.setLocation(p.x-d,p.y-c);

  • Have HTML content on Tabbed Panes

    I'm trying to add HTML content to tabbed panes in an Applet environment.
    Here is the code:
    import java.awt.*;
    import javax.swing.*;
    <APPLET
    CODE = tabbedpane.class
    WIDTH = 400
    HEIGHT = 200 >
    </APPLET>
    public class tabbedpane extends JApplet
    public void init()
    Container contentPane = getContentPane();
    JTabbedPane jtabbedpane = new JTabbedPane();
    JPanel jpanel1 = new JPanel();
    JPanel jpanel2 = new JPanel();
    JPanel jpanel3 = new JPanel();
    jpanel1.add(new JLabel("This is panel 1"));
    jpanel2.add(new JLabel("This is panel 2"));
    jpanel3.add(new JLabel("This is panel 3"));
    jtabbedpane.addTab("Tab 1",
    new ImageIcon("tab.jpg"),
    jpanel1, "This is tab 1");
    jtabbedpane.addTab("Tab 2",
    new ImageIcon("tab.jpg"),
    jpanel2, "This is tab 2");
    jtabbedpane.addTab("Tab three",
    new ImageIcon("tab.jpg"),
    jpanel3, "This is tab 3");
    contentPane.setLayout(new BorderLayout());
    contentPane.add(jtabbedpane);
    Could anyone tell me how can i add html content to this panes?
    Thanks
    Cesar

        JLabel l = new JLabel ("<html><font color = 'blue'>Hello world</font>") ;Foxcoming

  • Problem in tabbed panes

    hai friends,
    i am trying to create a tabbed pane which contains 3 panes.(top)
    and i try to add a tabbed pane at bottom of first pane which is a panel.
    i have set the size of panel as panel.setPreferredSize(new Dimension(750, 475));
    Now i am finding i cannot view the tabbed panes added to the panel.
    the relevant code is given below.
    some one have any idea..
    panel.add(new JScrollPane(textArea));
    panel.add(new JScrollPane(table));
    panel.setPreferredSize(new Dimension(750, 475));
    panel.setBackground(Color.PINK);
    JTabbedPane tabbedPane2 = new JTabbedPane     (JTabbedPane.BOTTOM);
    tabbedPane2.add("Result",new JTable(10,10));
    tabbedPane2.add("Message",new JTextArea());
    panel.add(tabbedPane2);
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("name1", new JScrollPane(panel));
    tabbedPane.addTab("name2",
         new JScrollPane(new JTextArea(5, 5)));
    tabbedPane.addTab("ANALYSIS", new JButton("<   HAI ALL   >"));
    container.add(tabbedPane);
    tabbedPane.setBackground(Color.ORANGE);

    i am giving the code i have done for the development of schema browser.
    i have some what overcome the problem i have faced. but i know its not a proper way.
    i am not able to use other layouts successfully to arrange these components.The layout now i have is not good enough.
    may be because i am beginner.
    kindly give your comments.....
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.border.BevelBorder;
    public class Trial1 extends JFrame implements ActionListener {
         Container container = null;
         private JTextArea textArea;
         private JTextArea result = new JTextArea();
         private JButton connection;
         private JButton execute;
         private ResultSet rs;
         private Connection con;
         public Trial1(String title) {
              super(title);
              container = this.getContentPane();
              container.setBackground(Color.BLACK);
              menu();
              panes();
              makeConnection();
              container.setLayout(new FlowLayout());
              this.setSize(800, 575);
              show();
         void menu() {
              JMenuBar menuBar = new JMenuBar();
              container.add(menuBar, FlowLayout.LEFT);
              menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
              menuBar.setForeground(Color.blue);
              JMenu file = new JMenu("File");
              JMenu edit = new JMenu("Edit");
              JMenu query = new JMenu("Query");
              menuBar.add(file);
              menuBar.add(edit);
              menuBar.add(query);
              file.add(new JMenuItem("New"));
              file.add(new JMenuItem("Open"));
              file.add(new JMenuItem("Save"));
              file.add(new JMenuItem("Save As"));
              file.addSeparator();
              file.add(new JMenuItem("Exit"));
              edit.add(new JMenuItem("Undo"));
              edit.addSeparator();
              edit.add(new JMenuItem("Cut"));
              edit.add(new JMenuItem("Copy"));
              edit.add(new JMenuItem("Paste"));
              edit.addSeparator();
              edit.add(new JMenuItem("Delete"));
              edit.add(new JMenuItem("Select All"));
              query.add(new JMenuItem("Compile"));
              query.add(new JMenuItem("Run"));
              query.add(new JMenuItem("Execute"));
              setJMenuBar(menuBar);
         void panes() {
              JPanel panel = new JPanel();
              textArea = new JTextArea(4, 50);
              textArea.setBorder(BorderFactory.createLineBorder(Color.black));
              JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.BOTTOM);
              JTable table = new JTable(5,10);
              tabbedPane2.add("Result",table);
              table.setBorder(BorderFactory.createLineBorder(Color.black));
              tabbedPane2.add("Message",result);
              tabbedPane2.setPreferredSize(new Dimension(750, 350));
              tabbedPane2.setBackground(Color.ORANGE);
              connection = new JButton("Connection");
              panel.add(connection);
              execute = new JButton("    Execute       ");
              execute.addActionListener(this);
              panel.add(execute);
              panel.add(new JScrollPane(textArea));
              panel.add(tabbedPane2);
              //panel.add(new JScrollPane(table));
              panel.setPreferredSize(new Dimension(750, 475));
              panel.setBackground(Color.PINK);
              //panel.setLayout(new GridLayout(2,3));
              JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
              tabbedPane.addTab("QUERY", new JScrollPane(panel));
              tabbedPane.addTab("SCHEMA BROWSER",
                        new JScrollPane(new JTextArea(5, 5)));
              tabbedPane.addTab("ANALYSIS", new JButton("<   HAI ALL   >"));
              container.add(tabbedPane);
              tabbedPane.setBackground(Color.ORANGE);
         public void actionPerformed(ActionEvent e) {
              Object src = e.getSource();
              /* myArea.getDocument().addDocumentListener( */
              if (src == execute) {
                   String query = textArea.getText();
                   try {
                        Statement smt;
                        smt = null;
                        smt = con.createStatement();
                        rs = smt.executeQuery(query);
                        while (rs.next()) {
                             result.append(rs.getString(1) + "\t" + rs.getInt(2)
                                       + "\n");
                        smt.close();
                   } catch (Exception ae) {
                        ae.printStackTrace();
         void makeConnection() {
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con = DriverManager.getConnection("jdbc:odbc:jmc", "sa", "sprint");
                   //con.close();
                   System.out.println("Connection successfully estabilished.");
              } catch (Exception ae) {
                   ae.printStackTrace();
         public static void main(String arg[]) {
              Trial1 trial = new Trial1(
                        "trials.");
    }

  • Hiding tabbed panes-should be enabled only on certain event

    Hi,
    I desperately need help. I'm still new to swings and thus need help.I'm writing an swing application where i have tabbed panes just like a tree i.e
    main1,main2
    under main1 have have another set of tabbed panes. Now i have to enable only the first pane and inside that pane there is a button which should enable the other pane and so forth. I just cannot figure how i should go about doing it. Any help is appreciated.
    ashah

    I tried doing that the new problem that i came across is that -
    here is the sample of the code. This is on the similar lines like i have written the code
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class tabbedPaneDemo extends JPanel
    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel panel1 = new JPanel();
    JPanel mainPanel1 = new JPanel();
    public tabbedPaneDemo()
    Component panel1 = makePanel1();
    tabbedPane.addTab("Panel1", panel1);
    tabbedPane.setSelectedIndex(0);
    setLayout(new GridLayout(1, 1));
    add(tabbedPane);
    Component makePanel1()
         JButton next = new JButton("Next");
         buttonListener listener = new buttonListener();
         next.addActionListener(listener);
         mainPanel1.add(next);
         return mainPanel1;
    class buttonListener implements ActionListener
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == "Next")
                   tabbedPane.removeTabAt(0);
                   tabbedPane.addTab("Panel2",null,makePanel2());
                   tabbedPane.setSelectedIndex(0);
                   JButton next1 = new JButton("Next1");
                   buttonListener listener = new buttonListener();
                   next1.addActionListener(listener);
                   panel1.add(next1);
              if(e.getSource() == "Next1")
                   tabbedPane.setEnabledAt(0,false);
                   tabbedPane.addTab("Panel3",null,makePanel3());
                   tabbedPane.setSelectedIndex(1);
    Component makePanel2()
         return panel1;
    Component makePanel3()
         JPanel mainPanel = new JPanel();
         return mainPanel;
    public static void main(String args[])
         tabbedPaneDemo demo = new tabbedPaneDemo();
         JPanel p = new JPanel(new BorderLayout());
         p.add(demo,BorderLayout.NORTH);
         JFrame frame1 = new JFrame("TabbedPaneDemo");
         frame1.addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent e)
              System.exit(0);
         frame1.getContentPane().add(p, BorderLayout.CENTER);
         frame1.setSize(400, 125);
    frame1.setVisible(true);
    I know there is a very simple mistake that i'm making but i can't figure where.

  • Tabbed Panes and Threads

    Is there a way to add a listener to a tabbed pane in such a way that by activating a particular tab a sleeping thread wakes up? In particular, if I have an audio window on a tabbed pane, I want it to pause when that pane is not in focus and start when it is again activated.

    Sure, read the JTabbedPane API and look for the add... methods to find a Listener you can add to your tabbed pane.

  • Tabbed Pane Enabling Color

    How Can I change TAbbed PAne Enabling Color ???
    Default color is gray and it's not very nice ...
    Thanks!

    Here it is with your line added. If this doesn't adequately demonstrate your requirements (the disabled tab color is orange), you're going to have to be a little more descriptive.
    import javax.swing.*;
    import java.awt.*;
    class JTabbedPaneDemo extends JFrame {
        public static void main(String[] args) {
            new JTabbedPaneDemo().go();
        void go() {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(300, 150);
            UIManager.put("TabbedPane.selected", Color.GREEN);
            JPanel panel1 = new JPanel();
            panel1.setBackground(Color.BLUE);
            panel1.add(new JLabel("Foo"));
            JPanel panel2 = new JPanel();
            panel2.setBackground(Color.MAGENTA);
            panel2.add(new JLabel("Bar"));
            JTabbedPane tabs = new JTabbedPane();
            tabs.addTab("Tab 1", panel1);
            tabs.addTab("Tab 2", panel2);
            tabs.setForegroundAt(0, Color.BLACK);
            tabs.setBackgroundAt(0, Color.GREEN);
            tabs.setForegroundAt(1, Color.RED);
            tabs.setBackgroundAt(1, Color.ORANGE);
            tabs.setEnabledAt(1, false); // Here you go, lazybones.
            getContentPane().add(tabs);
            getContentPane().setBackground(Color.YELLOW);
            setVisible(true);
    }

  • How can I make a tabbed pane transparent ?

    I have a tabbed pane placed on a JPanel with an image background. I added a tabbed pane with tabbedPane.setOpaque (false), however I still can't see the image behind the components that were added as tabs in the tabbedpane. Any help will be greatly appreciated.
    Here's a simplified version of the code:
    public class Example extends JPanel {
         public Example() {
              tabs = new JTabbedPane();
              tabs.setOpaque (false);
              JPanel tp1 = new JPanel();
              tp1.setOpaque(false);
              tabs.addTab ("panel 1", tp1);
              this.add (tabs);
         public void paintComponent(Graphics g) {
              // Paint background image
              g.drawImage(...);
    }

    Perhaps the opaque property is internally overset by the tab pane.
    Try this:
       public class Example extends JPanel {
          public Example() {
             JTabbedPane tabs = new JTabbedPane() {
                public boolean isOpaque() {
                   return false;
             JPanel tp1 = new JPanel() {
                public boolean isOpaque() {
                   return false;
             tabs.addTab("panel 1", tp1);
             this.add (tabs);
          public void paintComponent(Graphics g) {
             // Paint background image
             g.drawImage(...);
       } Regards.

Maybe you are looking for