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 8268259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:49:08+00:00 2026-06-08T05:49:08+00:00

Currently I am working on a swing application, consisting of a frame with splitpanel.

  • 0

Currently I am working on a swing application, consisting of a frame with splitpanel. In the left panel I have a jtree, listing all the countries in the world, in the right panel I have an OpenStreetMap, showing a map at startup (which works).
The nodes of the jtree are linked to the valueChanged(..) event handler:

/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    mapPanel = drawOpenStreetMap(45, 65, 12);
    mapPanel.repaint();
    repaint();
    splitPane.repaint();
    repaint();
    updateUI();
}

MapPanel drawOpenStreetMap(double lon, double lat, int zoom) {
    mapPanel = new MapPanel(); // just a JPanel extension, add to any swing/awt container
    mapPanel.setZoom(zoom); // set some zoom level (1-18 are valid)
    Point position = mapPanel.computePosition(new Point2D.Double(lon, lat));
    mapPanel.setCenterPosition(position); // sets to the computed position
    mapPanel.repaint(); // if already visible trigger a repaint here
    return mapPanel;
}

The valueChanged method gets called on clicking on a jtree node and the drawOpenStreetMap get called indeed and I expected the map to update and show a new location. But nothing changes. The map created at startup remains visible unaltered. The code of the valueChange method shows a number of repaint() calls etc. I have tried, to no avail.

Here is a pointer to the MapPanel source code.

Would be greatful if somebody could tell me how to update the map. Thanks in advance!

Postscript: I refered to the wrong MapPanel; it must be this one.

  • 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-06-08T05:49:09+00:00Added an answer on June 8, 2026 at 5:49 am

    It seems that you didn’t add the MapPanel instance you created to the parent container like SplitPanel in the valueChanged() methods.

    When valueChanged() method invoked, you call drawOpenStreetMap() method to create a MapPanel instance, however, you didn’t add it to the SplitPanel. That’s why the new location of map didn’t appear. Perhaps you need to insert the code like the following:

    public void valueChanged(TreeSelectionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    
        mapPanel = drawOpenStreetMap(45, 65, 12);
        rightPanel.add(mapPanel); // rightPanel is the panel in the right side of split pane.
        ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all, I'm currently working on a Java Swing application and I was looking
I'm working on a Swing application (currently running on Java 1.6 update 11) which
I am currently working on a SWING frame with a JScrollPane (including a JComponent),
I am programming in Java, using Swing. I am currently working with an application
Currently working on a Swing application and I need to use a ListSelectionListener to
I am working on a swing application which primarily includes a JTree and some
I'm currently working on a console window in Swing. It's based on a JTextArea
I'm currently working on a (rather large) pet project of mine , a Swing
I'm currently working on a small console application. This application is based on a
I'm currently working on a GUI based application and am using the code-generation feature

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.