From 5e1f26ee1bf9a731c04f66f0352c9eeece920f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Wed, 4 Sep 2024 13:30:27 +0300 Subject: [PATCH] add 'x' for tab close --- .../gui/TemplateGeneratorTabbedPane.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/io/projectdiscovery/nuclei/gui/TemplateGeneratorTabbedPane.java b/src/main/java/io/projectdiscovery/nuclei/gui/TemplateGeneratorTabbedPane.java index 4986b50..152eaab 100644 --- a/src/main/java/io/projectdiscovery/nuclei/gui/TemplateGeneratorTabbedPane.java +++ b/src/main/java/io/projectdiscovery/nuclei/gui/TemplateGeneratorTabbedPane.java @@ -78,7 +78,28 @@ public void addTab(TemplateGeneratorTab templateGeneratorTab) { final String tabName = Optional.ofNullable(templateGeneratorTab.getName()) .orElseGet(() -> "Tab " + this.openedTabCounter++); templateGeneratorTab.setName(tabName); + + JPanel tabPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + tabPanel.setOpaque(false); + JLabel tabLabel = new JLabel(tabName); + JButton closeButton = new JButton("x"); + closeButton.setMargin(new Insets(0, 5, 0, 5)); + closeButton.setBorderPainted(false); + closeButton.setContentAreaFilled(false); + closeButton.setFocusPainted(false); + closeButton.setOpaque(false); + closeButton.addActionListener(e -> { + int index = this.indexOfTabComponent(tabPanel); + if (index != -1) { + this.remove(index); + } + }); + + tabPanel.add(tabLabel); + tabPanel.add(closeButton); + this.addTab(tabName, templateGeneratorTab); + this.setTabComponentAt(this.getTabCount() - 1, tabPanel); this.setSelectedIndex(this.getTabCount() - 1); }