我正在JTabbedPane
添加JFrame
.
每个选项卡都包含一个不同的bgPanel
(JPanel
以绘制的图像为背景),每个选项卡都bgPanel
包含JScrollPane
,并且每个选项卡都JScrollPane
包含一个JPane
( nowyPanel
)。
bgPanels
只是一个背景。每个JScrollPane
都有setOpaque(false);
和getViewport().setOpaque(false);
。每个JPanel
nowyPanel
只有一个setOpaque(false);
。
我可以看到背景,JScrollPanels
但没有JPanels
。我检查了一下,似乎内容已正确添加到那里。问题在于JPanels
哪个没有出现。
这是一些代码:
static class JBackgroundPanel extends JPanel {
private BufferedImage img;
JBackgroundPanel() {
try {
img = ImageIO.read(new File("2.jpg"));
} catch (IOException e) {
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
//method to add components to element of array nowyPanel[] JPanel
//i[a] and o are set earlier and they are fine
static void skrotyDoPaneli() {
int a, b;
for (a = 0; a < o; a++) {
for (b = 0; b < i[a]; b++) {
nowyPanel[a].add(new dodanieIkony(ikonki[a][b], podpisyIkonek[a][b], listaOdnosnikow[a][b]));
nowyPanel[a].repaint();
nowyPanel[a].revalidate();
}
}
}
//set properties for all panels
static void ladowaniePaneli() {
int b;
Dimension osiemsetnaszescset = new Dimension(800, 600);
for (b = 0; b < o; b++) {
bgPanel[b] = new JBackgroundPanel();
vertical[b] = new JScrollPane();
nowyPanel[b] = new JPanel();
((FlowLayout) bgPanel[b].getLayout()).setVgap(0);
bgPanel[b].setPreferredSize(osiemsetnaszescset);
nowyPanel[b].setPreferredSize(osiemsetnaszescset);
vertical[b].setPreferredSize(new Dimension(789, 517));
vertical[b].setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
vertical[b].setOpaque(false);
nowyPanel[b].setOpaque(false);
vertical[b].getViewport().setOpaque(false);
vertical[b].add(nowyPanel[b]);
bgPanel[b].add(vertical[b]);
vertical[b].add(nowyPanel[b]);
}
}
//each element of bgPanel array is set as individual tab
static JTabbedPane tabbedPane() {
JTabbedPane panelZakladek = new JTabbedPane();
int j;
for (j = 0; j < o; j++) {
panelZakladek.addTab(nazwyGrup[j], bgPanel[j]);
}
return panelZakladek;
}
//does everything what needs to be done before JFrame shows up
static void przedStartem() throws FileNotFoundException, IOException {
odczyt();
odczytPaneli();
ladowaniePaneli();
skrotyDoPaneli();
}
//does przedStartem() and then initialize JFrame with content
public static void main(String[] args) throws FileNotFoundException, IOException {
przedStartem();
//przywolanie do zycia okna glownego JFrame
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
glowneOkno okno = new glowneOkno();
okno.setVisible(true);
}
});
}
//Variables Declaration
static int o = 0;
static int[] i = new int[1000];
static JBackgroundPanel[] bgPanel = new JBackgroundPanel[1000];
static JScrollPane[] vertical = new JScrollPane[1000];
static JPanel[] nowyPanel = new JPanel[1000];
static FileSystemView fsv = FileSystemView.getFileSystemView();
static String[] nazwyGrup = new String[1000];
static File plikZGrupami = new File("grupy.txt");
static String[][] podpisyIkonek = new String[1000][1000];
static Icon[][] ikonki = new Icon[1000][1000];
static String[][] listaOdnosnikow = new String[1000][1000];
static File[][] listaPlikow = new File[1000][1000];