Skip to content

Instantly share code, notes, and snippets.

@mpen
Created December 5, 2009 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpen/249641 to your computer and use it in GitHub Desktop.
Save mpen/249641 to your computer and use it in GitHub Desktop.
ラベルにアイコンとテキストを表示
// ラベルにアイコンとテキストを表示
// テキストはアイコンの下中央
import java.awt.Font
import javax.swing._
import javax.swing.plaf.FontUIResource
object JavaSwingTest1 {
def init() = {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
}
def main(args: Array[String]) = {
SwingUtilities.invokeLater {
new Runnable {
def run() {
init()
MyFrame.createAndShow
}
}
}
}
}
object MyFrame {
def createAndShow(): Unit = {
val frame = new MyFrame
frame.init()
frame.pack()
frame.setVisible(true)
}
}
class MyFrame private extends JFrame {
private def init(): Unit = {
setTitle("JavaSwingTest")
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
add(label)
}
lazy val label = new JLabel {
setText("Label")
setIcon(new ImageIcon("1.png"))
setVerticalTextPosition(SwingConstants.BOTTOM)
setHorizontalTextPosition(SwingConstants.CENTER)
setHorizontalAlignment(SwingConstants.CENTER)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment