我目前正在开发一个项目,我希望能够通过拖动鼠标而不是使用按钮来调整 JTextField 组件的大小,我遇到了 Rob Camick 的Resizing Components Class但我不知道如何实现/调用它我的课,希望有任何帮助,我的代码如下。提前致谢。
import java.awt.BorderLayout;
import java.awt.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.LinkedList;
import java.io.*;
import javax.swing.*;
public class Sheet implements Runnable {
LinkedList<Field> fieldList = new LinkedList<Field>();
JFrame frame = new JFrame("Swing Testing...");
public void run() {
Insets insets = frame.getInsets();
frame.setLayout(null);
JButton btn = new JButton("New");
JMenuBar menuBar = new JMenuBar();
JButton saveBtn = new JButton("Save");
JButton loadBtn = new JButton("Load");
JButton loadTempBtn = new JButton("Load From Template");
Dimension size = btn.getPreferredSize();
btn.setBounds(insets.left,insets.top,
size.width, size.height);
btn.setLocation(25, 50);
menuBar.setBounds(insets.left,insets.top,
size.width, size.height);
size = saveBtn.getPreferredSize();
saveBtn.setBounds(insets.left,insets.top,
size.width, size.height);
saveBtn.setLocation(500, 30);
size = loadBtn.getPreferredSize();
loadBtn.setBounds(insets.left,insets.top,
size.width, size.height);
loadBtn.setLocation(550, 30);
size = loadTempBtn.getPreferredSize();
loadTempBtn.setBounds(insets.left,insets.top,
size.width, size.height);
loadTempBtn.setLocation(600, 30);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
btn.setText("You Clicked me!");
FieldTypeFrame(e);
}
});
墨色风雨
相关分类