java如何做一个jframe能够收起如下图
能够在点<<Details按钮后收起文本框并且按钮显示为Details>>,在点Details>>按钮后显示文本框并且按钮显示为<<Details求代码。...
能够在点<<Details按钮后收起文本框并且按钮显示为Details>>,在点Details>>按钮后显示文本框并且按钮显示为<<Details求代码。
展开
1个回答
展开全部
大概的如下所示:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class DetailsFrame extends JFrame implements ActionListener {
boolean isFold = true;
JTextArea area = null;
JScrollPane scrollpane = null;
public DetailsFrame() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton btn = new JButton(">>Details");
btn.addActionListener(this);
panel.add(btn);
add(panel, BorderLayout.NORTH);
area = new JTextArea();
scrollpane = new JScrollPane();
scrollpane.setVisible(false);
scrollpane.setViewportView(area);
add(scrollpane, BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 100);
setVisible(true);
}
public static void main(String[] args) {
new DetailsFrame();
}
public void actionPerformed(ActionEvent e) {
JButton btn = (JButton) e.getSource();
if (isFold) {
scrollpane.setVisible(true);
setSize(400, 300);
btn.setText("<<Details");
isFold = false;
} else {
scrollpane.setVisible(false);
setSize(400, 100);
btn.setText(">>Details");
isFold = true;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询