簡體   English   中英

無法使用quaqua外觀

[英]Unable to use the quaqua look and feel

我已經下載了quaqua 8軟件包。 我將其quaqua.jar壓縮並將quaqua.jar文件放置在項目的工作庫中。

在此處輸入圖片說明

然后在主要方法中,我申請了Quaqua外觀。 但是我收到一個錯誤消息,說ch.randelshofer.quaqua package doesn't exist 為什么會這樣呢?

在此處輸入圖片說明

我還需要做其他事情嗎?

也列在編譯庫中:

在此處輸入圖片說明

我使用的IDE是NetBeans,操作系統是Windows。

來自Netbeans的輸出/ Win OS /相同的導入庫; Quaqua左,Mac OS X右。

在此處輸入圖片說明在此處輸入圖片說明

  1. 項目清單

從代碼

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.event.*;

public class JListDisabledItemDemo implements ItemListener, Runnable {

    private JFrame f = new JFrame("Colors");
    private static final String ITEMS[] = {" black ", " blue ", " green ",
        " orange ", " purple ", " red ", " white ", " yellow "};
    private JList jList;
    private JCheckBox[] checkBoxes;
    private boolean[] enabledFlags;

    @Override
    public void run() {
        JPanel pnlEnablers = new JPanel(new GridLayout(0, 1));
        pnlEnablers.setBorder(BorderFactory.createTitledBorder("Enabled Items"));
        checkBoxes = new JCheckBox[ITEMS.length];
        enabledFlags = new boolean[ITEMS.length];
        for (int i = 0; i < ITEMS.length; i++) {
            checkBoxes[i] = new JCheckBox(ITEMS[i]);
            checkBoxes[i].setSelected(true);
            checkBoxes[i].addItemListener(this);
            enabledFlags[i] = true;
            pnlEnablers.add(checkBoxes[i]);
        }
        jList = new JList(ITEMS);
        jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jList.setSelectionModel(new DisabledItemSelectionModel());
        jList.setCellRenderer(new DisabledItemListCellRenderer());
        jList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    System.out.println("selection");
                }
            }
        });
        JScrollPane scroll = new JScrollPane(jList);
        scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        Container contentPane = f.getContentPane();
        contentPane.setLayout(new GridLayout(1, 2));
        contentPane.add(pnlEnablers);
        contentPane.add(scroll);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocation(240, 280);
        UIManager.put("List.background", Color.lightGray);
        UIManager.put("List.selectionBackground", Color.orange);
        UIManager.put("List.selectionForeground", Color.blue);
        UIManager.put("Label.disabledForeground", Color.magenta);
        SwingUtilities.updateComponentTreeUI(f);
        f.pack();
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                f.setVisible(true);
            }
        });
    }

    @Override
    public void itemStateChanged(ItemEvent event) {
        JCheckBox checkBox = (JCheckBox) event.getSource();
        int index = -1;
        for (int i = 0; i < ITEMS.length; i++) {
            if (ITEMS[i].equals(checkBox.getText())) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            enabledFlags[index] = checkBox.isSelected();
            jList.repaint();
        }
    }

    public static void main(String args[]) {
        System.setProperty("Quaqua.tabLayoutPolicy", "wrap");
        try {
            UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel());
        } catch (Exception e) {
        }

        /*try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                System.out.println(info.getName());
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }*/
        SwingUtilities.invokeLater(new JListDisabledItemDemo());
    }

    private class DisabledItemListCellRenderer extends DefaultListCellRenderer {

        private static final long serialVersionUID = 1L;

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component comp = super.getListCellRendererComponent(list, value, index, false, false);
            JComponent jc = (JComponent) comp;
            if (enabledFlags[index]) {
                if (isSelected & cellHasFocus) {
                    comp.setForeground(Color.black);
                    comp.setBackground(Color.red);
                } else {
                    comp.setBackground(Color.white);
                    comp.setForeground(Color.black);
                }
                if (!isSelected) {
                    if ((value.toString()).trim().equals("yellow")) {
                        comp.setForeground(Color.blue);
                        comp.setBackground(Color.yellow);
                    } else if ((value.toString()).trim().equals("black")) {
                        comp.setForeground(Color.red);
                        comp.setBackground(Color.black);
                    }else if ((value.toString()).trim().equals("orange")) {
                        comp.setForeground(Color.blue);
                        comp.setBackground(Color.orange);
                    }
                }
                return comp;
            }
            comp.setEnabled(false);
            return comp;
        }
    }

    private class DisabledItemSelectionModel extends DefaultListSelectionModel {

        private static final long serialVersionUID = 1L;

        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (enabledFlags[index0]) {
                super.setSelectionInterval(index0, index0);
            } else {
                /*The previously selected index is before this one,
                 * so walk forward to find the next selectable item.*/
                if (getAnchorSelectionIndex() < index0) {
                    for (int i = index0; i < enabledFlags.length; i++) {
                        if (enabledFlags[i]) {
                            super.setSelectionInterval(i, i);
                            return;
                        }
                    }
                } /*
                 * Otherwise, walk backward to find the next selectable item.
                 */ else {
                    for (int i = index0; i >= 0; i--) {
                        if (enabledFlags[i]) {
                            super.setSelectionInterval(i, i);
                            return;
                        }
                    }
                }
            }
        }
    }
}

Quaqua外觀官方頁面上的通知:

Supported Platforms

The Quaqua Look and Feel supports Apple's J2SE 1.4, J2SE 5 and J2SE 6 
and SoyLatte J2SE 6 on Mac OS X 10.4 and 10.5.

Altough Quaqua works with J2SE 6, it provides limited support for features 
which go beyond J2SE 5.

The Quaqua native libraries support PowerPC and Intel Macs with 32-bits
or 64-bit processors. Quaqua will work without these native libraries, 
but user experience degrades.

Due to copyright restrictions and technical constraints, Quaqua can be 
run on non-Mac OS X systems for development purposes only.
FAQ
Can I use Quaqua on other platforms than Mac OS X?

No, you can't, except for development purposes.
This is because the Aqua user interface can only be licensed from Apple 
for use on Mac OS X.

Even if Apple would license it for use on other platforms, you wouldn't 
want to do it if you care about your users.
Aqua does not just look different than other user interfaces, it feels 
different as well. For example, when compared with the Windows UX 
interface, differences can be found in the set of keyboard accelerators, 
the focus behavior, the selection behavior, the modality of dialogs and 
in the use of transition and animation effects.

有了此許可證,我建議您使用其他(今天和更好的) 自定義外觀

IDE將“ ch”下的紅色突出顯示添加到您的代碼中,我想您尚未將該jar文件正確添加到類路徑中。 仔細閱讀IDE的文檔(正在使用的是Netbeans),看看它們如何告訴您將外部jar添加到項目中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM