JMenuBar under JTabbedPane

I have a JFrame, with a JPanel on it, with a JTabbedPane, with 3 tabs each with a JPanel. Then I add a JMenuBar to the Frame and the menus slide underneither the JTabbedPane. How can I fix this?
Thanks,
Marcus.

One just like this, please.
[url #"style="font-size:275px;background:url(http://www.ekmpowershop.co.uk/ekmps/shops/tyrrell123/images/doughnut.gif)"]__

Similar Messages

  • Underlying JTabbedPane paints through

    I have a problem where i'm updating some Components on a tab and when that tab is not the currently selected tab the components paint through onto whatever tab is selected. I've tried setting the visibility of the JPanels that are changing to false and then true when that tab is selected but that doesn't seem to work. Any ideas?

    The tab where I'm updating the components is made up of 3 Jpanels, each one is updated with a chart component (the chart is removed, a new one is created and then added to the JPanel). I am using absolute positioning (I calculate the x,y coords based on the chart size and center it in the JPanel). It only occurs when the charts are being updated and a different tab is selected and as soon as I switch to a diferent tab everything redraws fine.

  • Popup menu on tab components disables JTabbedPane mouse clicks

    When I add a popup menu to the tab components, the underlying JTabbedPane doesn't respond to any mouse click. How can we solve this?
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo extends JFrame {
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JMenuItem jMenuItem1;
        private JPopupMenu jPopupMenu1;
        private JTabbedPane jTabbedPane1;
        public TabPopupDemo() {
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(400, 300);
            setLocationRelativeTo(null);
            jPopupMenu1 = new JPopupMenu();
            jMenuItem1 = new JMenuItem("jMenuItem1");
            jTabbedPane1 = new JTabbedPane();
            jLabel1 = new JLabel("jLabel1");
            jLabel2 = new JLabel("jLabel2");
            jPopupMenu1.add(jMenuItem1);
            jTabbedPane1.addTab(null, jLabel1);
            jTabbedPane1.addTab(null, jLabel2);
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            int tabCount = jTabbedPane1.getTabCount();
            for (int i = 0; i < tabCount; i++) {
                JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
                jTabbedPane1.setTabComponentAt(i, jLabel);
                jLabel.setName(String.valueOf(i));
                jLabel.setComponentPopupMenu(jPopupMenu1);
            jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
                public void popupMenuCanceled(final PopupMenuEvent evt) {
                public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {
                public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
                    JPopupMenu source = (JPopupMenu) evt.getSource();
                    JLabel invoker = (JLabel) source.getInvoker();
                    JLabel component = (JLabel) jTabbedPane1.getComponentAt(Integer.parseInt(invoker.getName()));
                    jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
        public static void main(final String args[]) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TabPopupDemo().setVisible(true);
    }

    I don't know what the best solution would be.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo2 extends JFrame {
      private JLabel jLabel1;
      private JLabel jLabel2;
      private JMenuItem jMenuItem1;
      private JPopupMenu jPopupMenu1;
      private JTabbedPane jTabbedPane1;
      public TabPopupDemo2() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);
        jPopupMenu1 = new JPopupMenu();
        jMenuItem1 = new JMenuItem("jMenuItem1");
        jTabbedPane1 = new JTabbedPane();
        jLabel1 = new JLabel("jLabel1");
        jLabel2 = new JLabel("jLabel2");
        jPopupMenu1.add(jMenuItem1);
        jTabbedPane1.addTab(null, jLabel1);
        jTabbedPane1.addTab(null, jLabel2);
        getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        int tabCount = jTabbedPane1.getTabCount();
        TabMouseListener tml = new TabMouseListener(jTabbedPane1);
        for (int i = 0; i < tabCount; i++) {
          JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
          jTabbedPane1.setTabComponentAt(i, jLabel);
          jLabel.setName(String.valueOf(i));
          jLabel.addMouseListener(tml);
          jLabel.setComponentPopupMenu(jPopupMenu1);
        jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
          public void popupMenuCanceled(PopupMenuEvent evt) {}
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            //JPopupMenu source = (JPopupMenu) e.getSource();
            //JLabel invoker = (JLabel) source.getInvoker();
            int index = jTabbedPane1.getSelectedIndex();
            JLabel invoker = (JLabel) jTabbedPane1.getTabComponentAt(index);
            JLabel component = (JLabel) jTabbedPane1.getComponentAt(index);
            jMenuItem1.setText(invoker.getText() + ":  " + component.getText());
      static class TabMouseListener extends MouseAdapter{
        private final JTabbedPane tp;
        TabMouseListener(JTabbedPane tabbedPane) {
          this.tp = tabbedPane;
        private void dispatchEvent(MouseEvent me) {
          JLabel l = (JLabel)me.getSource();
          tp.dispatchEvent(SwingUtilities.convertMouseEvent(l,me,tp));
        public void mouseClicked(MouseEvent me)  { dispatchEvent(me); }
        public void mouseEntered(MouseEvent me)  { dispatchEvent(me); }
        public void mouseExited(MouseEvent me)   { dispatchEvent(me); }
        public void mousePressed(MouseEvent me)  { dispatchEvent(me); }
        public void mouseReleased(MouseEvent me) { dispatchEvent(me); }
      public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { new TabPopupDemo2().setVisible(true); }
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TabPopupDemo3 extends JFrame {
      private JLabel jLabel1;
      private JLabel jLabel2;
      private JMenuItem jMenuItem1;
      private JPopupMenu jPopupMenu1;
      private JTabbedPane jTabbedPane1;
      public TabPopupDemo3() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setSize(400, 300);
        setLocationRelativeTo(null);
        jPopupMenu1 = new JPopupMenu();
    //     jPopupMenu1 = new JPopupMenu() {
    //       public void show(Component c, int x, int y) {
    //         int i = jTabbedPane1.indexAtLocation(x, y);
    //         if(i>=0) {
    //           JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
    //           JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
    //           jMenuItem1.setText(tab.getText() + ":  " + component.getText());
    //           super.show(c, x, y);
        jMenuItem1 = new JMenuItem("jMenuItem1");
        jTabbedPane1 = new JTabbedPane();
        jTabbedPane1.setComponentPopupMenu(jPopupMenu1);
        jLabel1 = new JLabel("jLabel1");
        jLabel2 = new JLabel("jLabel2");
        jPopupMenu1.add(jMenuItem1);
        jTabbedPane1.addTab(null, jLabel1);
        jTabbedPane1.addTab(null, jLabel2);
        getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        int tabCount = jTabbedPane1.getTabCount();
        for (int i = 0; i < tabCount; i++) {
          JLabel jLabel = new JLabel("Testing the tab" + (i + 1));
          jTabbedPane1.setTabComponentAt(i, jLabel);
          jLabel.setName(String.valueOf(i));
          //jLabel.setComponentPopupMenu(jPopupMenu1);
        jPopupMenu1.addPopupMenuListener(new PopupMenuListener() {
          public void popupMenuCanceled(final PopupMenuEvent evt) {}
          public void popupMenuWillBecomeInvisible(final PopupMenuEvent evt) {}
          public void popupMenuWillBecomeVisible(final PopupMenuEvent evt) {
            JPopupMenu source = (JPopupMenu) evt.getSource();
            int i = jTabbedPane1.getSelectedIndex();
            JLabel tab = (JLabel) jTabbedPane1.getTabComponentAt(i);
            JLabel component = (JLabel) jTabbedPane1.getComponentAt(i);
            if(tab.getMousePosition()!=null) {
              jMenuItem1.setText(tab.getText() + ":  " + component.getText());
            }else{
              jMenuItem1.setText("aaaaaaaaa");
      public static void main(final String args[]) {
        EventQueue.invokeLater(new Runnable() {
          public void run() { new TabPopupDemo3().setVisible(true); }
    }

  • How to remove the line under JMenuBar

    Some client requires that the line under a JMenuBar looks ugly and it should be removed. can anybody give me some idea how to do it?

    Snap!
    JMenuBar menuBar = ...;
    menuBar.setBorderPainted(false);Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • AffineTransform problem caused by JMenuBar + JTabbedPane

    Hello everyone.
    I am starting to think that there is a bug in Java, because otherwise what else could cause the problem I am experiencing? Namely: adding a panel with a vertical text (like a Y axis caption) using an AffineTransform (see SSCCE below) causes this text to be misplaced in some cases.
    Variant A
    Panel is added directly to the application frame. This causes no problems and everything is as it should be.
    Variant B
    Panel is placed on a tabbed pane and a menu bar is associated with the frame. The vertical text is now shifted away from the place where it should be by the height of the menu bar plus the height of tabs on the tabbed pane. Why is this happening? Am I doing something wrong?
    Moreover, when one switches to another tab and then back, the text is now shifted only by the height of the tabs. Once the application window is resized at least a bit, the text jumps right back to the position shifted by tab height plus menu bar height... Strange, strange, strange...
    SSCCE
    import java.awt.*;
    import java.awt.font.FontRenderContext;
    import java.awt.geom.*;
    import javax.swing.*;
    class MyPanel extends JPanel {
        MyPanel() {
            this.setPreferredSize(new Dimension(300, 200));
        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2D = (Graphics2D)g;
            int g2DWidth = this.getWidth();
            int g2DHeight = this.getHeight();
            // Horizontal line in the middle of the panel (indicates the position
            // where the middle of the vertical label should be)
            g2D.drawLine(30, (int)(g2DHeight / 2), g2DWidth - 10,
                    (int)(g2DHeight / 2));
            // Vertical label
            AffineTransform origTransform = g2D.getTransform();
            AffineTransform rotate = AffineTransform.getRotateInstance(
                    -Math.PI / 2.0, 0, 0);
            g2D.setTransform(rotate);
            String text = "Centered?";
            FontRenderContext frc = g2D.getFontRenderContext();
            Font font = UIManager.getFont("Label.font");
            Rectangle2D bounds = font.getStringBounds(text, frc);
            g2D.drawString(text, -(int)((g2DHeight + bounds.getWidth()) / 2), 20);
            g2D.setTransform(origTransform);
    class Main {
        private static void createAndShowGUI() {
            // Menu bar
            JMenuBar menuBar = new JMenuBar();
            JMenu menu = new JMenu("Menu");
            JMenuItem menuItem = new JMenuItem("Menu Item");
            menu.add(menuItem);
            menuBar.add(menu);
            // Tabbed pane
            JTabbedPane tabbedPane = new JTabbedPane();
            JPanel panel = new MyPanel();
            tabbedPane.add(panel);
            JLabel label = new JLabel("Nothing interesting's going on here...");
            tabbedPane.add(label);
            // Frame
            JFrame frame = new JFrame();
            // TRICKY PART HERE =========================================
            // [(Un)comment lines as necessary]
            // Variant A: the panel only --------------------------------
            //frame.add(panel);
            // Variant B: menu bar + panel on a tabbed pane -------------
            frame.setJMenuBar(menuBar);
            frame.add(tabbedPane);
            // ==========================================================
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Thanks for any help.
    Best regards,
    vt
    Edited by: -vt- on 23-Apr-2010 13:08

    You are ignoring the current transform on the Graphics, use the following instead of setTransform():
    g2D.rotate(-Math.PI / 2.0, 0, 0);

  • JMenuBar hides under Canvas

    Hello,
    I am doing a program that has a JMenuBar and Canvas,
    The Menu Bar shows but when i click on it the JMenuItems are not shown they are hidden under the canvas which is stretched on the frame,
    when i dont add the canas the menu bar works .
    Thanks for help.

    Don't mix AWT (Canvas) and Swing (JMenuBar) unless you have very strong reasons and know what you are doing. Instead of a Canvas, can you use a JPanel? Hopefully all is in a Swing root container such as a JFrame or JApplet.

  • JMenubar hidden under JScrollPane

    Hi,
    JDK 1.3
    quick question... is there any way to stop JMenuItems in a JMenu, displayed on a JMenubar at the top of a Swing application from hidding behind the content of a Frame below it?
    I.e. when the FILE JMenu option is selected the drop down menu is hidden behind the content of the Frame.
    is there anyway to ensure the JMenuItems are always displayed 'on top'?
    The Frame is used to encapsulate the platform's WWW browser, displaying webpages. The class used to build this native frame extends java.awt.Canvas (this is the only way we could get around NT proxy server authentication) and therefore cannot be changed to use a JEditiorPane or JPane.
    Any ideas?

    All SWING components are lightweight. But you can make all popup menus to be heavyweight (like in AWT) for this call first the static method javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);

  • Loss of keyboard focus in Java appl running under linux

    I have a small sample program that replicates my problem. When this program is run a window is created. If you select File->New another instance of the program window is created. Now if you try to go back and bring to front the first window, keyboard focus is not
    transferred when run under linux. You can only type in the second window. The expected behavior does happen in Windows.
    > uname -a
    Linux watson 2.6.20-1.2933.fc6 #1 SMP Mon Mar 19 11:38:26 EDT 2007 i686 i686 i386 GNU/Linux
    java -versionjava version "1.5.0_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
    javac -versionjavac 1.5.0_11
    import java.awt.event.*;
    import javax.swing.*;
    class SwingWindow extends JFrame {
        SwingWindow() {
         super("SwingWindow");
         JMenuBar menuBar = new JMenuBar();     
            JMenu fileMenu = new JMenu("File");
            JMenuItem newItem = new JMenuItem("New");
            newItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
              SwingWindow.createAndShowGUI();
         fileMenu.add(newItem);
            menuBar.add(fileMenu);
            setJMenuBar(menuBar);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);       
         JTextField text = new JTextField(200);
         getContentPane().add(text);
         pack();
         setSize(700, 275);
        public static void createAndShowGUI() {
            JFrame frame = new SwingWindow();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    You can implement the FocusListener interface. When
    the first JFrame gains focus, call
    text.requestFocusInWindow(). I hope this helps.The call requestFocusInWindow is not helping, perhaps even making it worse.
    The problem seems to be that I am in the situation where the call
    KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()
    is returning the expected Component. The problem is that the KeyListener class that is registered with the Component is not being called when a key is being pressed.
    The issue is that I have a component that has the keyboard focus, but the KeyListener class
    is not responding.
    This seems to be a linux only problem which makes it only mysterious.

  • Adding a JMenuBar

    I am trying to create a simple JMenuBar in the application enlosed below.
    I keep getting the following error when ever i compile
    "Screen.java": Error #: 300 : method setJMenuBar(javax.swing.JMenuBar) not found in class random.Screen at line 67, column 9". Can some one please enlighten me.
    Class Screen is the main class. This is where the GUI is set up. it calls class Canvas which in turn calls class Nodes. GUI draws a bus network which holds a minimum of two nodes and a maximum of 10. The node number is under user control. The aim is to allow a user to select the configure menu to update the number of nodes on display in the GUI.
    package random;
    import javax.swing.JPanel;
    import javax.swing.border.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    * <p>Title: Simulation of the random load balancing algorithm </p
    public class Screen extends JPanel {
    static int screenWidth = (int)(Toolkit.getDefaultToolkit().getScreenSize().width*0.85);
    static int screenHeight = (int)(Toolkit.getDefaultToolkit().getScreenSize().height*0.95);
    private Container container;
    JButton add;
    Canvas canvas;
    JMenuBar menubar;
    JMenu configure;
    Thread animatorThread;
    RandomApplet RApplet;
    public Screen(RandomApplet RApplet){
         this.RApplet = RApplet;
         makeGui();
    public Screen(){
         makeGui();
    public void makeGui(){
    addMenu();
    GridBagLayout gridbag = new GridBagLayout();
         setLayout(gridbag);
         GridBagConstraints c = new GridBagConstraints();
         c.insets = new Insets(1,1,1,1);
         //add drawing canvas
         canvas = new Canvas();
         c.gridx = 0;
         c.gridy = 0;
         c.weightx=1.0;
         c.weighty=1.0;
         c.fill=GridBagConstraints.BOTH;
         gridbag.setConstraints(canvas, c);
         add(canvas);
         c.gridx=0;
         c.gridy=1;
         gridbag.setConstraints(canvas,c);
         add(add=addButton("Add"));
    private void addMenu(){
         menubar = new JMenuBar();
    setJMenuBar(menubar);
         configure = new JMenu("Configure");
         configure.add(new JMenuItem("add"));
         menubar.add(configure);
    private JButton addButton(String name) {
              JButton b = new JButton(name);
              ButtonHandler handler=new ButtonHandler();
              b.addActionListener(handler);
              b.setFont(new Font("Dialog", Font.BOLD, 12));
              b.setMargin(new Insets(0,0,0,0));
              return b;
    class ButtonHandler implements ActionListener{
         public void actionPerformed(ActionEvent e){
              if (e.getSource()== add){
                   if (canvas.addNode()){
                   repaint();
    public void run(){
         Thread thisThread = Thread.currentThread();
         while (animatorThread == thisThread){
              try {
              Thread.sleep(100);}
              catch (Exception e){
              break;}
    public static void main(String[] args) {
    JFrame f=new JFrame("Random");
         f.setSize(screenWidth, screenHeight);
         f.getContentPane().add(new Screen());
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    //class Canvas
    package random;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.util.*;
    import java.awt.Graphics;
    import java.awt.image.*;
    import javax.swing.*;
    public class Canvas extends JPanel{
    int width, height;
    Dimension size;
    Image canvasImage = null;
    Graphics canvasGraphics;
    Image networkMem;
    int NodeWidth, NodeHeight;
    Nodes[] n;
    int numberOfNodes;
    int x1, y1,x2,y2;
    public Canvas(){
    // canvas a perfect square
         height = 400;
         width = 400;
         size=new Dimension(width,height);
         setBackground(Color.white);
         networkMem=Toolkit.getDefaultToolkit().createImage("images/computer6.gif");
         NodeWidth = networkMem.getWidth(this);
    NodeHeight = networkMem.getHeight(this);
         //network must hold a minimum of 2 nodes
         n = new Nodes[11];
         n[0] = new Nodes(0,this);
         n[1] = new Nodes(1,this);
         numberOfNodes = 2;
    public void paintComponent(Graphics g)
    super.paintComponent(g);
         //create canvas image
         if (canvasImage==null){
              canvasImage=createImage(getSize().width,getSize().height);
              canvasGraphics = canvasImage.getGraphics();
         //adjust above to fit canvas window
    if ((canvasImage.getWidth(this) != getSize().width) || (canvasImage.getHeight(this) != getSize().height)){
         canvasImage = createImage(getSize().width,getSize().height);
              if (canvasImage!=null){
              canvasGraphics.dispose();
              canvasGraphics = canvasImage.getGraphics();
         //create a rectangular border outlining canvas area
         canvasGraphics.drawRect(0,0,getSize().width-1,getSize().height-1);
         x1=width-100;
         y1=height-100;
         x2=width-300;
         y2=width-100;
    canvasGraphics.drawLine(x1,y1,x2,y2);
    //canvasGraphics.drawLine(width-300,height-100,width-300,height-50);
         //canvasGraphics.drawLine(width-100,height-100,width-100,height-50);
         for(int i=0; i<numberOfNodes; i++){
         n.drawNode(canvasGraphics);
         g.drawImage(canvasImage, 0, 0, this);
         super.paintComponent(canvasGraphics);
    public int getNumberOfNodes()
         return numberOfNodes;
    public boolean addNode(){
         //add a node to network
         if (numberOfNodes < 10) {
         n[numberOfNodes]= new Nodes(numberOfNodes, this);
         numberOfNodes++;
         repaint();
         return true;
         return false;
    public boolean removeNode(){
         boolean removed = false;
         if (numberOfNodes >2) {
         numberOfNodes=numberOfNodes - 1;
         removed = true;
         else{
         removed = false;
         repaint();
         return removed;
    //class Nodes
    package random;
    import javax.swing.JPanel;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Graphics;
    public class Nodes{
    int nodeNumber;
    Canvas canvas;
    public Nodes(int number, Canvas c) {
    //each node has a number id
         nodeNumber=number;
         canvas=c;
    public void drawNode(Graphics g){
         if (nodeNumber%2 == 0){
    canvas.x1=canvas.x1-10;
         System.out.println(""+canvas.x1);
         g.drawLine(canvas.x1,canvas.y1,canvas.x1,canvas.y2-50);
         g.drawImage(canvas.networkMem,canvas.x1,canvas.y1-80,canvas);
         else{
         canvas.x1=canvas.x1-30;
         System.out.println(""+canvas.x1);
         g.drawLine(canvas.x1,canvas.y1,canvas.x1,canvas.y2+50);
         g.drawImage(canvas.networkMem,canvas.x1,canvas.y2+50,canvas);

    Thanks for the reply but i figured it out in the end.
    I can make use of the following commands
    setMenuBar(MenuBar mb)
    getMenuBar()
    to set the main frame menubar to that declared in addmenu() .
    if I add the following code to main() in the screen class the menu appears
    Screen screen = new Screen(null);
    f.setJMenuBar(screen.getMenuBar());

  • JTabbedPane, JPane PROBLEM

    Hi!, I have a several problem with JApplet, this is the code:
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.*;
    public class NuevoApplet extends JApplet{
    JMenuBar menuBar;
    JMenu menuArchivo, submenu;
    JMenuItem menuNuevo;
    JTabbedPane Tabbed1 = new JTabbedPane();
    JPanel Panel = new JPanel();
    class EventHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   //Si se elige salir en el menu
                   if (e.getSource() == menuNuevo)
                        CreaTab();
    ActionListener eventHandler = new EventHandler();
    public void start(){}
    public void init () {
    try {
    UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
    } catch (Exception e) { }
    Panel.setBorder(BorderFactory.createEtchedBorder());
    Panel.setLayout(new java.awt.BorderLayout());
    this.Panel.updateUI();
    this.setContentPane(this.Panel);
    this.CreaMenus();
    this.getContentPane().add(this.Tabbed1,java.awt.BorderLayout.CENTER);
    initConnections();
    private void CreaMenus(){
    //Creamos la barra de men�s
    menuBar = new JMenuBar();
    this.setJMenuBar(menuBar);
    //Creamos el men� de Archivo
    menuArchivo = new JMenu("Archivo");
    menuBar.add(menuArchivo);
    //Creamos los elementos del men� archivo
    menuNuevo = new JMenuItem("Abrir Archivo *.hex");
    menuArchivo.add(menuNuevo);     
    public void initConnections()
    //se suscriben todas las componentes que quieren escuchar los eventos
         menuNuevo.addActionListener(eventHandler);
    public void CreaTab(){
    JPanel a = new JPanel();
    Entorno1 b = new Entorno1();
    a.add(new JButton("BOTON1"),java.awt.BorderLayout.CENTER);
    a.add(new JButton("BOTON2"),java.awt.BorderLayout.EAST);
    this.Tabbed1.addTab("Primera Pesta�a", b); --> PROBLEM, not insert the JPanel b extends Entorno1
         b.repaint();
         Tabbed1.invalidate();
    Tabbed1.getParent().invalidate();
    Tabbed1.validate();
    Tabbed1.repaint();
         this.Tabbed1.updateUI();
         /*this.Tabbed1.validate();
         this.Tabbed1.updateUI();
         this.Tabbed1.revalidate();*/
    public class Entorno1 extends JPanel{
    public void Entorno1(){
         setLayout(new BorderLayout());
         Border raisedBevel = BorderFactory.createRaisedBevelBorder();
    Border loweredBevel = BorderFactory.createLoweredBevelBorder();
    Border compound = BorderFactory.createCompoundBorder
    (raisedBevel, loweredBevel);
    this.setBorder(compound);
    this.add(new JButton("Boton1"),java.awt.BorderLayout.CENTER);
    this.add(new JButton("Boton2"),java.awt.BorderLayout.EAST);
    this.updateUI();
    this.setVisible(true);
    this.revalidate();
    this.repaint();
    } //Fin de la clase Applet16F84
    When I use b extends Entorno1 and I insert as JPanel of JTabbedPane, not show it.
    this.Tabbed1.addTab("Primera Pesta�a", b);
    But this yes show it:
    this.Tabbed1.addTab("Primera Pesta�a", a);
    Why ? ..
    Thanks !

    Your constructor is actually a method and not a constructor.
    Therefore calling new Entorno1() returns you a blank panel.
    change this
    public void Entorno1(){
    ...to this.
    public Entorno1(){that should do it..
    nes

  • JTabbedPane w/ Accelerator Keys

    I need to add accelerator keys to the tabs of a JTabbedPane, much like the accelerators in a JMenuItem (i.e. under-score for Alt-F, or CTRL-X, etc...).
    Any suggestions?
    Thanks!

    It doesn't support accelerator, but it does support mnemonics. Check out the API for more information.

  • ADF swing: JTabbedPane does not display column names.

    Hi all,
    I have created an ADF Panel, which allows the user to run a few simple queries against an Oracle database done using ADF view objects and ADF view links and ADF application module.
    From the data control area I drag and drop a view link containing a query into a JTabbedPane. But when I run the ADF panel, JTabbedPane does not display the column headers from the SQL as opposed to JScrollPane which does.
    Suppose you do a select * from departments(dep_id, manager, state_cd), you will see all column headers meaning dep_id, manager, state_cd, and under each column the corresponding data which was retuned by the SQL if you use JScrollPane. But if you use you use JTabbedPane then you would only see the data which was retuned by the SQL without seeing the column header names meaning dep_id, manager, state_cd.
    What do I need to do to make JTabbedPane display columns headers?
    I would appreciate your input.
    Thanks.
    Bobby A.

    Hi,
    JScrollPane should be used. You can add this into a JTabbedPane if you like. Not all Swing panel show table headers
    Frank

  • When does a JTabbedPane set the size of the component inside a tab?

    I would like to know how big a component inside a tab is directly after I've added it to a tab in a JTabbedPane.
    I thought once I've "added" a component via the JTabbedPane.add(String, Component) method, the Component would be realized with correct sizes.
    Where or when should I request the information about how big a component has become inside a tab??
    Example:
    1. "Add" a tab via the menu.
    2. Notice that the size of the panel has not changed even though we see it on the screen.
    -Js
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    public class TabbedPaneShowingTest extends JFrame
         //GUI
         private JTabbedPane tabbedPane;
              private JPanel tabPanel;
         //MENU
         private JMenuBar mainMenuBar;
              private JMenu actionMenu;
                   private JMenuItem addTabMenuItem;
         public TabbedPaneShowingTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getTabbedPane());
              this.setJMenuBar(getMainMenuBar());
              this.pack();
              this.setVisible(true);
         //GUI
         private JTabbedPane getTabbedPane()
              if(tabbedPane == null)
                   tabbedPane = new JTabbedPane();
                   tabbedPane.setPreferredSize(new Dimension(100,100));
              return tabbedPane;
         private JPanel getTabPanel()
              if(tabPanel == null)
                   tabPanel = new JPanel();
                   tabPanel.setBackground(Color.GREEN);
              return tabPanel;
         //MENU
         private JMenuBar getMainMenuBar()
              if(mainMenuBar == null)
                   mainMenuBar = new JMenuBar();
                   mainMenuBar.add(getActionMenu());
              return mainMenuBar;
         private JMenu getActionMenu()
              if(actionMenu == null)
                   actionMenu = new JMenu("Action");
                   actionMenu.add(getAddLineMenuItem());
              return actionMenu;
         private JMenuItem getAddLineMenuItem()
              if(addTabMenuItem == null)
                   addTabMenuItem = new JMenuItem("Add Tab");
                   addTabMenuItem.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                             System.out.println("BEFORE TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
                             getTabbedPane().add("Tab",getTabPanel());
                             System.out.println("AFTER TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
              return addTabMenuItem;
         public static void main(String args[])
              new TabbedPaneShowingTest();
    }

    Once again... a little experimenting is a good thing. Just use SwingUtilities.InvokeLater() to retrieve the proper size.
    -Js
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.SwingUtilities;
    public class TabbedPaneShowingTest extends JFrame
         //GUI
         private JTabbedPane tabbedPane;
              private JPanel tabPanel;
         //MENU
         private JMenuBar mainMenuBar;
              private JMenu actionMenu;
                   private JMenuItem addTabMenuItem;
         public TabbedPaneShowingTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getTabbedPane());
              this.setJMenuBar(getMainMenuBar());
              this.pack();
              this.setVisible(true);
         //GUI
         private JTabbedPane getTabbedPane()
              if(tabbedPane == null)
                   tabbedPane = new JTabbedPane();
                   tabbedPane.setPreferredSize(new Dimension(100,100));
              return tabbedPane;
         private JPanel getTabPanel()
              if(tabPanel == null)
                   tabPanel = new JPanel();
                   tabPanel.setBackground(Color.GREEN);
              return tabPanel;
         //MENU
         private JMenuBar getMainMenuBar()
              if(mainMenuBar == null)
                   mainMenuBar = new JMenuBar();
                   mainMenuBar.add(getActionMenu());
              return mainMenuBar;
         private JMenu getActionMenu()
              if(actionMenu == null)
                   actionMenu = new JMenu("Action");
                   actionMenu.add(getAddLineMenuItem());
              return actionMenu;
         private JMenuItem getAddLineMenuItem()
              if(addTabMenuItem == null)
                   addTabMenuItem = new JMenuItem("Add Tab");
                   addTabMenuItem.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                             System.out.println("BEFORE TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
                             getTabbedPane().addTab("Tab",getTabPanel());
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       System.out.println("AFTER TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
              return addTabMenuItem;
         public static void main(String args[])
              new TabbedPaneShowingTest();
    }

  • 24pt Font Size Tab Text for JTabbedPane

    I'm creating an app for use with Touchscreens and need to make the buttons and such, large enough to fit the tip of a finger.
    I'm having trouble with the JTabbedPane font size and am having trouble finding a way to make the text in the tab larger.
    Same issue with text in a border. Just for looks but would be nice.
    And the text in the window title.
    I've searched the forums and the tutorials but couldn't find anything. Thanks in advance for your assistance.
    Stone

    Hi,
    the text in the window's title is managed by the underlying OS. So, I guess there is no possibility to influence this text. Except you change the display properties of the OS on this computer that runs your app.
    Regards,
    Patrick

  • JTabbedPane - Adding Tab to the right

    In my program, I am using a JTabbedPane, which shows several settings pages. Now i want to add a "help" screen to it, in a new tab, but I would like to align that tab to the right, the same effect like adding a Box.createHorizontalGlue() to a JMenuBar.
    My question graphically: http://home.arcor.de/sidiousx/tab.gif
    I searched the API and I tried subclassing JTabbedPane and changing the UI (but I'd rather not subclass the UI, because I use different Look and Feels), but it wass all useless. Anyone got an idea?

    Hm and how would you do this?
    I tried to sub-class BasicTabbedPaneUI:
    class TabUI extends BasicTabbedPaneUI
        public Rectangle getTabBounds(int index, Rectangle rect)
            if (index == rects.length - 1) {
                rect = super.getTabBounds(index, rect);
                rect.x += 100;
                return rect;
            } else {
                return super.getTabBounds(index, rect);
    }But:
    1. It doesn't look good in Metal-LookAndFeel
    2. It doesn't work ;) If the last Tab is selected, you can see some kind of shadow, where the tab should be (in this test), but nothing more.

Maybe you are looking for