MCPcopy Create free account
hub / github.com/10cks/fofaEX / addPluginTab

Method addPluginTab

src/main/java/plugins/CommonTemplate.java:211–288  ·  view source on GitHub ↗
(JTabbedPane tabbedPane, String pluginName, String pluginJsonPath)

Source from the content-addressed store, hash-verified

209
210 // 点击运行新增 tab 页
211 public static void addPluginTab(JTabbedPane tabbedPane, String pluginName, String pluginJsonPath) {
212 // 检查标签是否已经存在
213 if (tabbedPane.indexOfTab(pluginName) != -1) {
214 int existingTabIndex = tabbedPane.indexOfTab(pluginName);
215 tabbedPane.removeTabAt(existingTabIndex);
216 }
217 //ActionListener在选择“关闭”时关闭标签页
218 ActionListener closeListener = event -> tabbedPane.removeTabAt(tabbedPane.indexOfTab(pluginName));
219
220 // 创建表格
221 JTable table = createTableFromJson(pluginJsonPath);
222 // 清理可能已经添加的菜单项
223 // 初始化 table 右键
224 RightClickFunctions.table = table;
225 RightClickFunctions.initializeTable();
226
227 // 重新设置表格头,以便新的渲染器生效
228 JTableHeader header = getjTableHeader(table);
229 table.setTableHeader(header);
230 // 自动调整列宽
231 adjustColumnWidths(table);
232 JScrollPane scrollPane = new JScrollPane(table);
233 // 设置表格的行高
234 table.setRowHeight(24);
235 table.setFillsViewportHeight(true);
236
237 JPanel mainPanel = new JPanel();
238 mainPanel.setLayout(new BorderLayout()); // 修改你的mainPanel的布局为 BorderLayout
239 mainPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
240
241 JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
242
243 mainPanel.add(scrollPane, BorderLayout.CENTER); // 把 scrollPane 添加到 BorderLayout.CENTER
244
245 saveTableData(tabbedPane);
246
247 //为标签添加了一个鼠标监听器,显示弹出菜单以关闭标签页
248 mainPanel.addMouseListener(new MouseAdapter() {
249 public void mousePressed(MouseEvent e) {
250 if (SwingUtilities.isRightMouseButton(e)) {
251 JPopupMenu menu = new JPopupMenu();
252 JMenuItem closeItem = new JMenuItem("关闭");
253 closeItem.addActionListener(closeListener);
254 menu.add(closeItem);
255 menu.show(e.getComponent(), e.getX(), e.getY());
256 }
257 }
258 });
259
260 // 导出表格
261 JButton exportButton = new JButton("Export to Excel");
262 exportButton.setFocusPainted(false); // 添加这一行来取消焦点边框的绘制
263 exportButton.setFocusable(false); // 禁止了按钮获取焦点,因此按钮不会在被点击后显示为"激活"或"选中"的状态
264
265 panel1.add(exportButton);
266 exportButton.addActionListener(new ActionListener() {
267 @Override
268 public void actionPerformed(ActionEvent e) {

Callers 1

executeCommandMethod · 0.95

Calls 5

createTableFromJsonMethod · 0.95
initializeTableMethod · 0.95
saveTableDataMethod · 0.95
getjTableHeaderMethod · 0.80
adjustColumnWidthsMethod · 0.80

Tested by

no test coverage detected