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

  • SEARCH
  • Home
  • 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 237747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:27:02+00:00 2026-05-11T20:27:02+00:00

This is in conjunction to the question posed here: JTabbedPane: Components before and after

  • 0

This is in conjunction to the question posed here:
JTabbedPane: Components before and after the tabs themselves

I want to attach a mouse listener that allows for dragging the constructed google chrome-like frame. Starting out, the initial dragging code is rather easy, and the mouse-dragging code at this Kirill-post can be used pretty much directly. I’d only want this behaviour if the user clicks and drags on the “title bar” of the frame, that is, the area where the tabs (the stick-uppers) reside. This is also easy – just change the dragging code to only accept clicks in the upper area of the JTabbedPane, the part that contains the tabs.

However, I want to reduce the grabbable area further, and only allow click-and-drag-frame in the area NOT occupied by the tabs (the stick-uppers – anyone have a better name for this GUI element?) – again quite like Google Chrome (Chrome also adds a bar above the tabs when in windowed mode, to easier get hold of the frame if many tabs are active. But Chrome do this perfect: It is possible to grab the window in the tabbed part that doesn’t have tabs, and even in the small v’s inbetween the tabs!)

What I’d effectively want to do, is to be able to attach the mouse listeners to the background of the GUI for the tabs – but how to accomplish something like this?

  • 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-11T20:27:02+00:00Added an answer on May 11, 2026 at 8:27 pm

    After looking at the solutions for this question (draggable tabs in Swing), I found that the actual TabbedPaneUI has some methods that can fix both problems: Only drag window in tab area, which turned out to be the hardest part, and not drag when above the tabs themselves. The relevant code follows, in the two sections marked with “// ::”. The code is adapted from the question-mentioned Kirill-code. The code doesn’t handle other cases than when the tabs are at top – which makes sense when considering what I want to do.

            // mouse listener for dragging the host window
            MouseAdapter adapter = new MouseAdapter() {
                int lastX;
                int lastY;
    
                boolean _dragInitiated;
    
                @Override
                public void mousePressed(MouseEvent e) {
                    TabbedPaneUI ui = _windowTabs.getUI();
    
                    // :: Won't drag if we're positioned above a tab in tab area
                    if (ui.tabForCoordinate(_windowTabs, e.getX(), e.getY()) != -1) {
                        _dragInitiated = false;
                        return;
                    }
    
                    // :: Won't drag if we're below the tab area
                    int maxY = 0;
                    for (int i = 0; i < _windowTabs.getTabCount(); i++) {
                        Rectangle bounds = ui.getTabBounds(_windowTabs, i);
                        int y = bounds.y + bounds.height;
                        if (y > maxY) {
                            maxY = y;
                        }
                    }
                    _dragInitiated = true;
                    if (maxY > 0) {
                        if (e.getY() > maxY) {
                            _dragInitiated = false;
                        }
                    }
    
                    Point eventLocationOnScreen = e.getLocationOnScreen();
                    if (eventLocationOnScreen == null) {
                        Component source = (Component) e.getSource();
                        eventLocationOnScreen = new Point(e.getX() + source.getLocationOnScreen().x, e.getY()
                                + source.getLocationOnScreen().y);
                    }
    
                    lastX = eventLocationOnScreen.x;
                    lastY = eventLocationOnScreen.y;
                }
    
                @Override
                public void mouseDragged(MouseEvent e) {
                    if (!_dragInitiated) {
                        return;
                    }
    
                    Point eventLocationOnScreen = e.getLocationOnScreen();
                    if (eventLocationOnScreen == null) {
                        Component source = (Component) e.getSource();
                        eventLocationOnScreen = new Point(e.getX() + source.getLocationOnScreen().x, e.getY()
                                + source.getLocationOnScreen().y);
                    }
    
                    int dx = eventLocationOnScreen.x - lastX;
                    int dy = eventLocationOnScreen.y - lastY;
                    Window win = POTabbedFrame.this;
                    Point loc = win.getLocation();
                    win.setLocation(loc.x + dx, loc.y + dy);
                    lastX = eventLocationOnScreen.x;
                    lastY = eventLocationOnScreen.y;
                }
            };
            _windowTabs.addMouseListener(adapter);
            _windowTabs.addMouseMotionListener(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Don't know if it will convert images or URLs, but… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer Static methods aren't inherently thread-safe. They're treated no differently by… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer Just make sure the first part or the URL ends… May 12, 2026 at 1:11 am

Related Questions

The issue I'm currently having is mapping multiple GUI fields to object properties (i.e.
I have a bunch of scripts - some in perl and some in bash
I need to delete my input file securely once I have finished with it,
I realize fast is a bit subjective so I'll explain with some context. I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.