1

I have a transparent GUI, but when I go to scroll the pane, it seems to just take the last pixel and stretch it.

Here is my mainGUI:

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);
}
}

This is my tabs Class:

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;
}

}

How do I make it so that the scrolling is clean and doesn't blur?

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi) – MadProgrammer Nov 16 '14 at 23:21

1 Answers1

1

Swing doesn't know how to deal with components that have transparent background colors, you can't use panel.setBackground(new Color(0, 0, 0, 0));, instead, simply use setOpaque and pass it false

Also, this panel = new JPanel(false); is not a good idea, you want to leave double buffering on, otherwise you will end up with a bunch of flickering each time the UI is updated

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366