Created
December 5, 2009 10:32
-
-
Save mpen/249641 to your computer and use it in GitHub Desktop.
ラベルにアイコンとテキストを表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ラベルにアイコンとテキストを表示 | |
// テキストはアイコンの下中央 | |
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