Skip to content

Commit

Permalink
add 'x' for tab close
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Sep 4, 2024
1 parent acad01d commit 5e1f26e
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 5e1f26e

Please sign in to comment.