Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to override paint() method from subclass of frame? #171

Unanswered
jingkaimori asked this question in Q&A
Discussion options

docs/SIP-8.md describes how to override paint method in subclass of Component, but this method cannot apply to subclass of Frame.

You must be logged in to vote

Replies: 2 comments

Comment options

Is it important that it is the frame itself? I think this is a rather low level scenario that was probably not covered for Scala-Swing. You could always install a single component that does the drawing:

import scala.swing._
import java.awt.Color
new Frame {
 contents = new Component {
 preferredSize = new Dimension(400, 400)
 
 override def paintComponent(g: Graphics2D): Unit = {
 g.setColor(Color.red)
 g.drawLine(0, 0, peer.getWidth, peer.getHeight)
 }
 }
 pack().centerOnScreen()
 open()
}

would this be suitable in your case?

You must be logged in to vote
0 replies
Comment options

Note that (not just in Scala Swing, but in Swing generally) every JFrame has a "content pane"; doing things with a JFrame often involves interacting with the content pane, rather than with the frame itself.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #170 on May 27, 2023 04:56.

AltStyle によって変換されたページ (->オリジナル) /