Skip to content

Commit

Permalink
Fixes #58 Tab MouseListener Cancels Tab Change and Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
deathmarine committed Nov 17, 2016
1 parent 15d23d8 commit 8245759
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/us/deathmarine/luyten/Model.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.deathmarine.luyten;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
Expand Down Expand Up @@ -124,7 +125,15 @@ public Model(MainWindow mainWindow) {
house = new JTabbedPane();
house.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
house.addChangeListener(new TabChangeListener());

house.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e) {
if(SwingUtilities.isMiddleMouseButton(e)){
Component comp = house.getComponentAt(e.getX(), e.getY());
closeOpenTab(house.getSelectedIndex());
}
}
});
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, 1));
panel.setBorder(BorderFactory.createTitledBorder("Code"));
Expand Down Expand Up @@ -163,15 +172,6 @@ public void run() {
int index = house.indexOfTab(title);
Tab ct = new Tab(title);
ct.getButton().addMouseListener(new CloseTab(title));
ct.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e) {
if(SwingUtilities.isMiddleMouseButton(e)){
int index = house.indexOfTab(title);
closeOpenTab(index);
}
}
});
house.setTabComponentAt(index, ct);
} else {
house.setSelectedIndex(house.indexOfTab(title));
Expand Down

0 comments on commit 8245759

Please sign in to comment.