滚动透明的GUI模糊文本,JAVA

时间:2014-11-16 23:19:14

标签: java swing transparency jscrollpane

我有一个透明的GUI,但是当我去滚动窗格时,它似乎只是取最后一个像素并拉伸它。

这是我的主菜:

public class MainGUI extends JPanel {
static final JFrame frame = new JFrame("GuildWars2 Map Overlay");

public ArrayList<Tabs> tabList = new ArrayList<Tabs>();
final JTabbedPane tabbedPane = new JTabbedPane();

int leftRight = 350;
int upDown    = 400;

String[] text = {"1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3",
                 "1.1","1.2","1.3","2.1","2.2","2.3","3.1","3.2","3.3","4.1","4.2","4.3","5.1","5.2","5.3","6.1","6.2","6.3"};
String[] text2 = {"Much WOW", "very seperated", "Such Tab"};
String[] emptyText = {"", "", ""};

ImageIcon icon = createImageIcon("");

public MainGUI() {
    Tabs p1 = new Tabs("Tab 1", icon, text, "");
    p1.makeTextPanel();
    p1.scrollFrame.setPreferredSize(new Dimension(leftRight, upDown));
    tabList.add(p1);

    Tabs p2 = new Tabs("Tab 2", icon, text, "");
    p2.makeTextPanel();
    p2.scrollFrame.setPreferredSize(new Dimension(leftRight, upDown));
    tabList.add(p2);

    Tabs p3 = new Tabs("Tab 3", icon, text, "");
    p3.makeTextPanel();
    p3.scrollFrame.setPreferredSize(new Dimension(leftRight, upDown));
    tabList.add(p3);

    Tabs p4 = new Tabs("Tab 4", icon, text2, "");
    p4.makeTextPanel();
    p4.scrollFrame.setPreferredSize(new Dimension(leftRight, upDown));
    tabList.add(p4);

    Tabs p5 = new Tabs("+", icon, emptyText, "");
    p5.makeTextPanel();
    p5.scrollFrame.setPreferredSize(new Dimension(leftRight, upDown));
    tabList.add(p5);

    for(int i=0; i<tabList.size(); i++){
        tabbedPane.addTab(tabList.get(i).title, tabList.get(i).image, tabList.get(i).scrollFrame, tabList.get(i).toolTip);
    }

    add(tabbedPane);
    //tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}


/*
 * Creates and displays the main application frame.
 */
public void display() {
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add content to the window.
    frame.add(this, BorderLayout.CENTER);

    //set ALL to clear //DONT Do
    //frame.setUndecorated(true);

    //set to clear
    frame.setBackground(new Color(0, 0, 0, 0));

    // Set's the window to be "always on top"
    frame.setAlwaysOnTop(true);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}
}

这是我的标签类:

public class Tabs {

public String    title;
public ImageIcon image;
public String[]  text;
public String    toolTip;
public JPanel    panel;

public JScrollPane scrollFrame;


Node[] node;

public Tabs(String _title, ImageIcon _image, String[] _text, String _toolTip){
    title = _title;
    image = _image;
    text = _text;
    toolTip = _toolTip;

}

public Tabs(Node[] _node){
    node = _node;
}

public void makeTextPanel() {
    panel = new JPanel(false);
    panel.setBackground(new Color(0, 0, 0, 0));
    panel.setLayout(new GridLayout((text.length/3), 3));
    for(int i=0; i<text.length; i++){
        JLabel filler = new JLabel(text[i]);
        //filler.setHorizontalAlignment(JLabel.LEFT);
        panel.add(filler);
    }
    scrollFrame = new JScrollPane(panel);
    scrollFrame.setBackground(new Color(0, 0, 0, 0));
    panel.setAutoscrolls(true);
    //this.add(scrollFrame);
    //return scrollFrame;
}

}

如何制作以使滚动干净且不模糊?

1 个答案:

答案 0 :(得分:1)

Swing不知道如何处理具有透明背景颜色的组件,您无法使用panel.setBackground(new Color(0, 0, 0, 0));,只需使用setOpaque并传递false

此外,这个panel = new JPanel(false);不是一个好主意,你想要保持双缓冲,否则每次更新UI时你都会有一堆闪烁