1

重複の可能性:
パネルの色が失われる

ファイル チューザーをアクティブにするボタンをクリックし、結果のファイルを追加すると、uimanager を使用してファイル チューザーを Windows チューザーとして表示すると、パネルの色が消えます。

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileSystemView;
import javax.swing.JFileChooser;
import javax.swing.plaf.FileChooserUI;

@SuppressWarnings("serial")
public class pan extends JPanel implements DropTargetListener {

    private DefaultListModel listModel = new DefaultListModel();
    private JButton addbutton;
    private JButton removebutton;
    private JButton selectbutton;
    private JButton lockbutton;
    private JButton unlockbutton;

    /**
     * Create the panel.
     */
    public pan() {
        setLayout(null);
        addbutton = new JButton("New button");
        addbutton.setBounds(10, 10, 90, 100);
        addbutton.addActionListener(new Action());
        add(addbutton);

        removebutton = new JButton("New button");
        removebutton.setBounds(110, 10, 90, 100);
        add(removebutton);

        selectbutton = new JButton("New button");
        selectbutton.setBounds(210, 10, 90, 100);
        add(selectbutton);

        lockbutton = new JButton("New button");
        lockbutton.setBounds(310, 10, 90, 100);
        add(lockbutton);

        unlockbutton = new JButton("New button");
        unlockbutton.setBounds(410, 10, 90, 100);
        add(unlockbutton);

        JLabel headerLabel = new JLabel("New label");
        headerLabel.setBorder(new BevelBorder(BevelBorder.RAISED,
            Color.LIGHT_GRAY, Color.GRAY, null, null));
        headerLabel.setUI(new ModifLabelUI());
        headerLabel.setBounds(10, 120, 635, 30);
        add(headerLabel);   
    }


    class Action implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            if(e.getSource()==addbutton){
                JFileChooser filechooser=new JFileChooser();
                filechooser.setMultiSelectionEnabled(true);             
                try {
    UIManager.setLookAndFeel(UIManager
            .getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (InstantiationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IllegalAccessException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (UnsupportedLookAndFeelException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

                filechooser.updateUI();
                filechooser.showOpenDialog(new pan());
                File files=filechooser.getSelectedFile();
                listModel.addElement(files);
        }       
    }
}

UImanger を削除すると問題は解決します

4

1 に答える 1

2

ドキュメントごとに...使用したいルックアンドフィールを使用するようにUIマネージャーが最初に設定されていることを確認したい場合があります...

編集具体的な例については、@see This Postを参照してください

public static void main(String[] args) {
    try {
            // Set System L&F
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
    } 
    catch (UnsupportedLookAndFeelException e) {
       // handle exception
    }
    catch (ClassNotFoundException e) {
       // handle exception
    }
    catch (InstantiationException e) {
       // handle exception
    }
    catch (IllegalAccessException e) {
       // handle exception
    }

    new SwingApplication(); //Create and show the GUI.
}
于 2012-11-17T20:28:24.230 に答える