Java - having buttons displaying arrows

回眸只為那壹抹淺笑 提交于 2019-12-05 04:00:18

Swing has a default arrow button class that is BasicArrowButton

Example:

    JFrame frame = new JFrame("Arrow Button Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new BasicArrowButton(BasicArrowButton.EAST), BorderLayout.EAST);
    frame.add(new BasicArrowButton(BasicArrowButton.NORTH), BorderLayout.NORTH);
    frame.add(new BasicArrowButton(BasicArrowButton.SOUTH), BorderLayout.SOUTH);
    frame.add(new BasicArrowButton(BasicArrowButton.WEST), BorderLayout.WEST);
    frame.pack();
    frame.setVisible(true);
sudocode

Using an ImageIcon on the button, or one of the Swing BasicArrowButtons is probably the best approach. However, you could also use Unicode arrow symbols. For example

\u25C4: ◄

\u2190: ←

\u25BA: ►

\u2192: →

Some resources:

You would need to ensure that the font(s) your application may use supports these symbols.

Just use a image:

ImageIcon icon = new ImageIcon("images/icon.gif");
JButton button2 = new JButton(icon);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!