2

ツールバー、トップ メニュー (ボタンを閉じる、最小化、最大化する場所) のルック アンド フィールを変更する方法

何か変化を好むことは可能ですか?(追加、削除ボタン、背景の割り当て) 作成に必要なインポートとは?

4

2 に答える 2

2

の背景画像を設定JButtonできます。これを見ることができます: Swing チュートリアル: JButtonを使用して をと でnew JButton(String text,ImageIcon imgIco)作成する方法を示します。JButtonImageIconString

使用できる背景とテキストの色を設定するにはsetBackground(Color c)setForeground(Color c)

また

または、サポートされている適切なルック アンド フィールを設定してルック アンド フィールのカラー スキームをカスタマイズし、そのコンポーネントのカラー スキーム/サイズなどを変更します。コンポーネントごとに何百もの変更が可能です。

ExitMinimizeMaximize Toolbar ボタンをカスタマイズするには、ルック アンド フィールを使用することもできます ( JFrame の Close/Minimize ボタンのカスタム デザイン)。

金属 ウィンドウズ

import java.awt.BorderLayout;
import javax.swing.*;

public class FrameCloseButtonsByLookAndFeel {

    FrameCloseButtonsByLookAndFeel() {
        String[] names = {
                UIManager.getSystemLookAndFeelClassName(), 
                UIManager.getCrossPlatformLookAndFeelClassName()
        };
        for (String name : names) {
            try {
                UIManager.setLookAndFeel(name);
            } catch (Exception e) {
                e.printStackTrace();
            }
            // very important to get the window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame f = new JFrame(UIManager.getLookAndFeel().getName());
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

            JPanel gui = new JPanel(new BorderLayout());
            f.setContentPane(gui);

            JTree tree = new JTree();
            tree.setVisibleRowCount(4);
            gui.add(tree, BorderLayout.LINE_START);

            gui.add(new JScrollPane(new JTextArea(3,15)));

            JToolBar toolbar = new JToolBar();
            gui.add(toolbar, BorderLayout.PAGE_START);
            for (int ii=1; ii<5; ii++) {
                toolbar.add(new JButton("Button " + ii));
                if (ii%2==0) {
                    toolbar.addSeparator();
                }
            }

            f.pack();

            f.setLocationByPlatform(true);
            f.setVisible(true);
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new FrameCloseButtonsByLookAndFeel();
            }
        });
    }
}
于 2012-08-10T16:52:06.650 に答える
0

フレームのタイトルバーの外観を変更する最も簡単な方法は、フレームを作成する前に LookAndFeel を設定することです。おそらくこれはあなたが探しているものです - http://www.jtattoo.net/ScreenShots.html

于 2012-08-10T16:54:06.150 に答える