Skip to content

Commit

Permalink
add 'x' for tab close (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir authored Sep 5, 2024
1 parent acad01d commit 4ff4507
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 4ff4507

Please sign in to comment.