java swing 嵌入地图_MapPanel:Java Swing Map API

1)查看他们发布的源代码,我将模拟他们在创建MapPanel GUI时所做的事情,就像这样

import java.awt.Dimension;

import javax.swing.*;

import com.roots.map.MapPanel.Gui;

public class TestMapPanel {

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

Gui mapPanel = new Gui();

mapPanel.setPreferredSize(new Dimension(722, 632));

JMenuBar menuBar = mapPanel.createMenuBar();

JFrame frame = new JFrame("Map Panel Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(mapPanel);

frame.setJMenuBar(menuBar);

frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

});

}

}

然后,用户可以通过简单地检查与信息面板相对应的JCheckBoxMenuItem来选择是否要查看信息面板.

2)和3)一切皆有可能,但是您需要研究源代码以了解如何最好地做到这些.

编辑,为了摆脱启动时的搜索面板,我采取了以下措施:

frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

SwingUtilities.invokeLater(new Runnable() {

public void run() {

for (int i = 0; i < menuBar.getMenuCount(); i++) {

JMenu menu = menuBar.getMenu(i);

if ("View".equals(menu.getText())) {

int componentCount = menu.getMenuComponentCount();

for (int j = 0; j < componentCount; j++) {

Component c = menu.getMenuComponent(j);

if (c instanceof JCheckBoxMenuItem) {

JCheckBoxMenuItem chkBoxMenuItem = (JCheckBoxMenuItem) c;

String text = chkBoxMenuItem.getText();

if ("Show SearchPanel".equals(text)) {

chkBoxMenuItem.doClick();

}

}

}

}

}

}

});

不必这么笨拙,如果我正确地阅读和解释了源代码,我认为源可能会更好.

1)查看他们发布的源代码,我将模拟他们在创建MapPanel GUI时所做的事情,就像这样 import java.awt.Dimension; import javax.swing.*; import com.roots.map.MapPanel.Gui; public class TestMapPanel { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { Gui mapPanel = new Gui(); mapPanel.setPreferredSize(new Dimension(722, 632)); JMenuBar menuBar = mapPanel.createMenuBar(); JFrame frame = new JFrame("Map Panel Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mapPanel); frame.setJMenuBar(menuBar); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } } 然后,用户可以通过简单地检查与信息面板相对应的JCheckBoxMenuItem来选择是否要查看信息面板. 2)和3)一切皆有可能,但是您需要研究源代码以了解如何最好地做到这些. 编辑,为了摆脱启动时的搜索面板,我采取了以下措施: frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { for (int i = 0; i < menuBar.getMenuCount(); i++) { JMenu menu = menuBar.getMenu(i); if ("View".equals(menu.getText())) { int componentCount = menu.getMenuComponentCount(); for (int j = 0; j < componentCount; j++) { Component c = menu.getMenuComponent(j); if (c instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem chkBoxMenuItem = (JCheckBoxMenuItem) c; String text = chkBoxMenuItem.getText(); if ("Show SearchPanel".equals(text)) { chkBoxMenuItem.doClick(); } } } } } } }); 不必这么笨拙,如果我正确地阅读和解释了源代码,我认为源可能会更好.
经验分享 程序员 微信小程序 职场和发展