CrazyProgrammer
CrazyProgrammer

Reputation: 544

Mouse Event on inner jpanel placed on another jpanel

I have one JPanel container in the background, which will move on mouse drag.

I have small inner jpanels placed on different parts of the background container. On each inner jpanels i have a line drawn on it. I want to show a menu only when they click on the lines in the inner panel, clicking on other places in the inner panel should be forwarded to the background panel.

Please help me how to do that.

Thanks.

Upvotes: 0

Views: 104

Answers (1)

StanislavL
StanislavL

Reputation: 57381

You can read this to understand how to work with glasspane. But I would draw lines directly on the main panel rather than multiple inner ones. For the lines you can create list of Shapes to be drawn. For each the Shape (Line) you can create a thick like (use BasicStroke with desired thickness) and detect click by asking the stroked line whether it contains the click coordinates.

Upvotes: 2

Related Questions