How to draw grid using swing class Java and detect mouse position when click and drag

There are any number of ways to get this to work, depending on what it is you want to achieve. This first example simply uses the 2D Graphics API to render the cells and a MouseMotionListener to monitor which cell is highlighted. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import … Read more

Image Greyscale with CSS & re-color on mouse-over?

There are numerous methods of accomplishing this, which I’ll detail with a few examples below. Pure CSS (using only one colored image) img.grayscale { filter: url(“data:image/svg+xml;utf8,<svg xmlns=\’http://www.w3.org/2000/svg\’><filter id=\’grayscale\’><feColorMatrix type=\’matrix\’ values=\’0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\’/></filter></svg>#grayscale”); /* Firefox 3.5+ */ filter: gray; … Read more

Text on image mouseover?

This is using the :hover pseudoelement in CSS3. HTML: <div id=”wrapper”> <img src=”http://placehold.it/300×200″ class=”hover” /> <p class=”text”>text</p> </div>​ CSS: #wrapper .text { position:relative; bottom:30px; left:0px; visibility:hidden; } #wrapper:hover .text { visibility:visible; } ​Demo HERE. This instead is a way of achieving the same result by using jquery: HTML: <div id=”wrapper”> <img src=”http://placehold.it/300×200″ class=”hover” /> <p … Read more