JLayeredPane and painting

As you found, a BufferedImage is an effective way to cache complex content for efficient rendering; CellTest is an example. A flyweight renderer, shown here, is another approach. Finally, I’ve re-factored your instructive example in a way that may make experimentation easier. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import … Read more

Drawing in JLayeredPane over exising JPanels

Here is a simple example that shows how you might (randomly) drag and drop a “chess piece” from one square to another: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class ChessBoard extends JFrame implements MouseListener, MouseMotionListener { JLayeredPane layeredPane; JPanel chessBoard; JLabel chessPiece; int xAdjustment; int yAdjustment; public ChessBoard() { Dimension boardSize = … Read more

tech