| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
88 バイト追加 、 2020年2月16日 (日) 04:28
編集の要約なし
==[[JTextComponent 4]]==
*エディターキットの利用[[エディターキット]]の利用
[[File:0743_jtext4.jpg]]
import javax.swing.Action;
import javax.swing.[[JFrame]]; import javax.swing.JMenuJ[[Menu]]; import javax.swing.JMenuBarJ[[Menu]]Bar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities[[Swing]]Utilities;
import javax.swing.text.StyledEditorKit;
*/
public class JTextTest4 {
private [[JFrame ]] frame;
private JTextPane txtPane;
* StyledEditorKit を利用する
*/
private JMenu getMenuJ[[Menu]] get[[Menu]]() { JMenu J[[Menu]] menu = new JMenuJ[[Menu]]("Style");
Action action = null;
menu.addSeparator();
menu.add(new StyledEditorKit.ForegroundAction("Red[[R]]ed", Color.red));
menu.add(new StyledEditorKit.ForegroundAction("Green", Color.green));
menu.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue));
}
private void createUI() {
frame = new [[JFrame]]("TextTest3"); frame.setDefaultCloseOperation([[JFrame]].EXIT_ON_CLOSE);
txtPane = new JTextPane();
JPanel basePanel = new JPanel(new BorderLayout());
basePanel.add(new JScrollPane(txtPane), BorderLayout.CENTERCENTE[[R]]);
// メニューを作成
JMenu J[[Menu]] menu = getMenuget[[Menu]](); JMenuBar J[[Menu]]Bar mb = new JMenuBarJ[[Menu]]Bar();
mb.add(menu);
frame.setJMenuBarsetJ[[Menu]]Bar(mb);
frame.getContentPane().add(basePanel);
}
public static void main(String[] args) {
SwingUtilities[[Swing]]Utilities.invokeLater( new Runnable[[R]]unnable(){
public void run() {
JTextTest4 jft = new JTextTest4();

案内メニュー