Hallo, ich habe ein Problem, was das Ändern der Größe meines Layouts angeht:
Wenn ich das Fenster verkleinere, falten sich die Komponenten einfach zusammen,
anstatt runterzuskalieren.
Das Layout sieht ca so aus:
Und zum starten:
Wie krieg ich das hin, dass die Kompenenten bei der Verkleinerung des Fensters proportional verkleinert werden?
Wenn ich das Fenster verkleinere, falten sich die Komponenten einfach zusammen,
anstatt runterzuskalieren.
Das Layout sieht ca so aus:
Java:
package javaapplication3;
import java.awt.*;
import javax.swing.*;
public class NewClass extends JFrame{
JLabel label;
JList serviceJList;
JScrollPane serviceListSP;
JButton startButton;
JButton stopButton;
JTextArea statusText;
JScrollPane statusTextSP;
Insets insets;
public NewClass()
{
this.setTitle("Test");
this.setLayout(new GridBagLayout());
GridBagConstraints c;
// <editor-fold defaultstate="collapsed" desc="Tab1">
label = new JLabel("Services");
insets = new Insets(10,5,0,5);
c = new GBC(0,0,1,1,0,0,GridBagConstraints.HORIZONTAL,
GridBagConstraints.PAGE_END,insets);
this.add(label,c);
c = new GridBagConstraints();
serviceJList = new JList();
serviceJList.setModel(
new javax.swing.AbstractListModel() {
String[] strings = { "Eintrag 1", "Eintrag 2", "Eintrag 3"};
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
serviceJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
serviceListSP = new JScrollPane(serviceJList);
insets = new Insets(10,0,10,1);
c = new GBC(1,0,1,2,1,0,GridBagConstraints.HORIZONTAL,
GridBagConstraints.PAGE_START,insets);
this.add(serviceListSP,c);
startButton = new JButton("Start");
startButton.setEnabled(false);
insets = new Insets(10,1,5,50);
c = new GBC(2,0,1,0,0,0,GridBagConstraints.HORIZONTAL,
GridBagConstraints.PAGE_START,insets);
this.add(startButton, c);
stopButton = new JButton("Stop");
stopButton.setEnabled(false);
insets = new Insets(10,1,0,50);
c = new GBC(2,1,1,1,0,0,GridBagConstraints.HORIZONTAL,
GridBagConstraints.PAGE_START,insets);
this.add(stopButton, c);
statusText = new JTextArea(5, 25);
statusTextSP = new JScrollPane(statusText);
statusText.setEditable(false);
insets = new Insets(10,10,10,10);
c = new GBC(0,4,4,1,0,0,GridBagConstraints.BOTH,
GridBagConstraints.LAST_LINE_START,insets);
this.add(statusTextSP,c);
// JPanel fill = new JPanel();
// insets = new Insets(0,0,0,0);
// c= new GBC(3,0,1,2,10,1,GridBagConstraints.BOTH,GridBagConstraints.CENTER
// ,insets);
// this.add(fill,c);
pack();
setVisible(true);
}
public class GBC extends GridBagConstraints
//each constructor sets the GridBagConstraints to te given variables
{
GridBagConstraints c;
public GBC(int x, int y, int width, int height)
{
this.gridx = x;
this.gridy = y;
this.gridheight = height;
this.gridwidth = width;
}
public GBC(int x, int y)
{
this.gridx = x;
this.gridy = y;
}
public GBC(int x, int y, int width, int height, double weightx, double weighty,
int fill, int anchor, Insets insets)
{
this.gridx = x;
this.gridy = y;
this.gridwidth = width;
this.gridheight = height;
this.weightx = weightx;
this.weighty = weighty;
this.fill = fill;
this.anchor = anchor;
this.insets = insets;
}
}
}
Und zum starten:
Java:
package javaapplication3;
public class Main
{
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new NewClass();
}
});
}
}