Hallo, bei folgendem code funktioniert setMaxiumSize komischerweise nicht.
Das ganze wurde mithilfe dem intellij gui designer erstellt.
Vielen Dank für eure Hilfe!
Das ganze wurde mithilfe dem intellij gui designer erstellt.
Java:
import javax.swing.*;
import java.awt.*;
import java.io.File;
public class GUI {
private JTextField destTextField;
private JTextField srcTextField;
private JButton applyButton;
private JButton chooseSrcButton;
private JButton chooseDestButton;
private JPanel JPanel;
private final JFileChooser fc = new JFileChooser();
public GUI() {
chooseSrcButton.addActionListener(e -> {
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if (fc.showDialog(JPanel, "choose file/directory") == JFileChooser.APPROVE_OPTION &&
fc.getCurrentDirectory().exists()) {
srcTextField.setText(fc.getSelectedFile().getPath());
}
});
chooseDestButton.addActionListener(e -> {
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
if (fc.showDialog(JPanel, "choose file/directory") == JFileChooser.APPROVE_OPTION &&
fc.getCurrentDirectory().exists()) {
destTextField.setText(fc.getSelectedFile().getPath());
}
});
applyButton.addActionListener(e -> {
File src = new File(srcTextField.getText()),
dest = new File(destTextField.getText());
if (src.exists() && dest.exists()) {
}
});
}
public static void main(String[] args) {
JFrame f = new JFrame("simple file synchronizer");
JPanel p = new GUI().JPanel;
f.setContentPane(p);
f.setPreferredSize(p.getPreferredSize());
f.setMaximumSize(p.getMaximumSize());
f.setMinimumSize(p.getMinimumSize());
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setVisible(true);
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
private void $$$setupUI$$$() {
JPanel = new JPanel();
JPanel.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(3, 2, new Insets(2, 2, 2, 2), -1, -1));
JPanel.setAutoscrolls(false);
JPanel.setInheritsPopupMenu(false);
JPanel.setMaximumSize(new Dimension(600, 200));
JPanel.setMinimumSize(new Dimension(500, 160));
JPanel.setPreferredSize(new Dimension(500, 108));
JPanel.setRequestFocusEnabled(true);
destTextField = new JTextField();
destTextField.setText("enter destination directory");
JPanel.add(destTextField, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
chooseSrcButton = new JButton();
chooseSrcButton.setText("choose");
JPanel.add(chooseSrcButton, new com.intellij.uiDesigner.core.GridConstraints(0, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
chooseDestButton = new JButton();
chooseDestButton.setText("choose");
JPanel.add(chooseDestButton, new com.intellij.uiDesigner.core.GridConstraints(1, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
srcTextField = new JTextField();
srcTextField.setText("enter source directory");
JPanel.add(srcTextField, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
applyButton = new JButton();
applyButton.setText("apply");
JPanel.add(applyButton, new com.intellij.uiDesigner.core.GridConstraints(2, 0, 1, 2, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return JPanel;
}
}
Vielen Dank für eure Hilfe!