packageMyCode;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JSplitP...
package MyCode;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.event.*;
@SuppressWarnings("serial")
public class TextFrame extends JFrame{
private JSplitPane jSplitPane= new JSplitPane();//窗体分割线
private JPanel jRightScrollPane= new JPanel();
private JPanel jLeftScrollPane = new JPanel();
private JButton bt1= new JButton("kk");
private JButton bt2= new JButton("kk");
public TextFrame()
{
jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
jSplitPane.setDividerLocation(170);//左边大小
jSplitPane.setLeftComponent(jLeftScrollPane);
jSplitPane.setRightComponent(jRightScrollPane);
jLeftScrollPane.add(bt1);
bt1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
jRightScrollPane.add(bt2);
}
});
this.add(jSplitPane);
this.setSize(400,500);
this.setLocation(200,100);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[]args)
{
new TextFrame();
}
}
为什么点击完左边的按钮后,要移动分割线,右边的按钮才会出现?怎么解决这个问题。
展开