【发布时间】:2013-04-25 17:29:39
【问题描述】:
JTabbedPane main_tabbedPane = new JTabbedPane( JTabbedPane.TOP );
main_tabbedPane.setBorder( new EmptyBorder( 0, 0, 0, 0 ) );
main_tabbedPane.setBounds( 10, 76, 665, 473 );
main_tabbedPane.setVisible(false);
main_content.add( main_tabbedPane ); // main_content is a jpanel
然后我调用一个扩展 JPanel 的类构造函数
alphaStarter_tab = new AlphaStarterPnl();
其中有一个 TextArea(来自 Java AWT 而不是 JTextArea)
public class AlphaStarterPnl extends JPanel {
private TextArea outputTxtA;
public AlphaStarterPnl(){
outputTxtA = new TextArea("",4,50,TextArea.SCROLLBARS_VERTICAL_ONLY);
outputTxtA.setFont(new Font("Tahoma", Font.PLAIN, 13));
outputTxtA.setEditable(false);
outputTxtA.setBackground(new Color(179,190,201));
outputTxtA.setForeground(new Color(34,64,132));
outputTxtA.setBounds(15, 133, 630, 300);
add(outputTxtA);
}
}
然后我将这个面板(它比粘贴的代码更多,但在这里无关紧要)添加到选项卡式窗格中
main_tabbedPane.addTab( "Copy Files", null, alphaStarter_tab, null );
当我这样做时,尽管 main_tabbedPane 已设置为 setvisible false,但 TextArea 会弹出,不仅如此,它还出现在三个地方。 (可能在 0,0 坐标处出现一次,然后在设置的 x,0 坐标处出现,然后在设置的 x,y 坐标处出现。当我在程序中继续时,当第二个选项卡出现时,这种“丑陋内容的闪光”消失了已添加。
有什么想法吗?
【问题讨论】:
-
不要使用文本区域。使用 JTextArea。不要使用 setBounds()。使用适当的布局管理器。
标签: java swing textarea awt jtabbedpane