Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:52+00:00 2026-05-26T02:41:52+00:00

I have a JFrame with four components: three JPanels and a JTabbedPane. Two panels

  • 0

I have a JFrame with four components: three JPanels and a JTabbedPane. Two panels have selectable components and are located approximately in BorderLayout.NORTH and EAST, while the JTabbedPane sits approximately in CENTER. The tabs of the TabbedPane are aligned on the bottom of the pane. I say approximately because the actual layout is done with a GridBagLayout (sorry!).

Currently, the focus traversal cycle goes like this:

Current Cycle:  
   1) North JPanel  
   2) East JPanel  
   3) JTabbedPane selected tab  
   4) JTabbedPane selected tab content  

However, I’d like it to be:

Desired Cycle:  
   1) North JPanel  
   2) JTabbedPane selected tab content  
   3) JTabbedPane selected tab  
   4) East JPanel  

I have tried the Vector-based FocusTraversalPolicy given by the Java Focus Guide with no luck: I couldn’t get the cursor to go down into the tab panel contents.

I then looked into extending/changing the other FocusTraversalPolicy classes out there, but got nowhere with that either.

I’m fairly sure the issue is the current FocusTraversalPolicy uses component location on screen to determine the layout cycle. Technically the side panel is higher on the screen than the center tabbed pane. I’d really like to change this though. Anybody else run into this/have any insight? Thanks!!

EDIT:

Here’s an SSCCE with proper layout code demonstrating the problem. Just a note: the issue is NOT the layout, as that has to stay the same.

package SO;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public class ssccee7729709{
    JPanel north;
    JPanel north2;
    JPanel east;
    JTabbedPane center;
    JFrame content;

    void initialize() {
        north = new JPanel(new FlowLayout()) {
            {
                this.setBackground(Color.CYAN);
            }
        };
        north.add(new JLabel("Title panel"));

        north2 = new JPanel(new FlowLayout()) {
            {
                this.setBackground(Color.RED);
            }
        };
        north2.add(new JLabel("north2 Panel"));
        north2.add(new JTextField(4));
        north2.add(new JTextField(4));

        east = new JPanel(new GridLayout(3,1)) {
            {
                this.setBackground(Color.BLUE);
            }
        };
        east.add(new JButton("b1"));
        east.add(new JButton("b2"));

        center = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.WRAP_TAB_LAYOUT);
        for (int i = 0; i < 2; i++) {
            JPanel panel = new JPanel(new GridLayout(4,1));
            panel.add(new JLabel("Panel " + i));
            panel.add(new JTextField(6));
            panel.add(new JTextField(6));
            panel.add(new JTextField(6));
            center.addTab("Tab " + i, panel);   
        }

        content = new JFrame();
        content.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        content.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        {
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridwidth = 4;
            gbc.weightx = 1;
            content.add(north, gbc);
        }
        {
            gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.BOTH;
            gbc.anchor = GridBagConstraints.PAGE_START;
            gbc.gridwidth = 1;
            gbc.weightx = 1;
            // gbc.weighty = .1;
            gbc.gridy = 1;
            gbc.gridx = 1;
            content.add(north2, gbc);
        }
        {
            gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridwidth = GridBagConstraints.RELATIVE;
            gbc.gridheight = GridBagConstraints.RELATIVE;
            gbc.weighty = 1;
            gbc.gridy = 2;
            content.add(center, gbc);
        }
        {
            gbc = new GridBagConstraints();
            gbc.fill = GridBagConstraints.VERTICAL;
            gbc.anchor = GridBagConstraints.SOUTHEAST;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.gridx = 3;
            gbc.gridheight = 4;
            content.add(east, gbc);
        }

      content.setVisible(true);
      content.pack();
    }

    public static void main(String args[]) {
        ssccee7729709 so = new ssccee7729709();
        so.initialize();
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:41:53+00:00Added an answer on May 26, 2026 at 2:41 am

    If you look at the source for LayoutFocusTraversalPolicy, which is the default policy, it pretty much just extends SortingFocusTraversalPolicy, which takes a Comparator<? extends Component>.

    You should be able to provide your own Comparator which is an inner class and so has access to parent components, and provide appropriate comparison values by looking at themselves and their parents.

    It probably wouldn’t hurt to check out the source to LayoutComparator which is what LayoutFocusTraveralPolicy uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JFrame with two JPanels inside. One is set on west, other
I have a JFrame with null layout and two one character JLabels on the
I have a JFrame which has 3 JPanels in GridBagLayout .. Now, when I
I have a JFrame with about 10 components (JLabel, Combobox, Buttons, TextFields). When I
I have a JFrame with BorderLayout as the layout manager. In the south border,
I have a JFrame that has a large number of changing child components. (Many
I have a JFrame object, and i need to support two JVM 1.5 on
I have a JFrame and following components. JButton = jButton1 Progress Bar = progressBar
I have a JFrame Gridlayout with components like buttons, JTextfields, JLabels. Sometimes when I
I have two JFrame Forms-SelectContactsfrm.java and Taskfrm.java. There is JTable in SelectContactsfrm file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.