Hallo Leute,
ich habe ein GroupLayout-Problem.
Ich will, das die Gruppe untereinander sein soll, und nicht links untreeinander.
Was mache ich falsch?
Peter
ich habe ein GroupLayout-Problem.
Code:
import static javax.swing.GroupLayout.Alignment.BASELINE;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.Point;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
public class splitPaneDemo {
JMenuBar menuBar;
JMenu fileMenu;
JMenuItem openItem, closeItem,schliessen;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
/* try {
// Studafis_2 window = new Studafis_2();
// window.frame.setVisible(true);
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}*/
// new Studafis_2_neu().setVisible(true);
new splitPaneDemo();
}
});
/* JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
// TODO Auto-generated method stub
sp.setDividerLocation(150);;
JFrame frame = new JFrame ("aaa");
frame.setVisible(true);
*/
}
public splitPaneDemo() {
super();
MyMenuBar();
// initialize6();
// initialize7();
// initialize8();
// with_Table_and_grouplayout();
// with_table_and_grouplayout_tutorials_de();
// with_table_and_grouplayout_2();
jtree_and_jsplitpane();// _docs_oracle_com();
}
private void MyMenuBar() {
menuBar = new JMenuBar();
fileMenu = new JMenu("Datei");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
openItem = new JMenuItem("öffnen");
fileMenu.add(openItem);
closeItem = new JMenuItem("close");
schliessen = new JMenuItem("Schließen");
fileMenu.add(closeItem);
fileMenu.add(schliessen);
menuBar.add(fileMenu);
// jframe.setJMenuBar(menuBar);
schliessen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
System.exit(0);
}
});
JMenu bearbeitenMenu = new JMenu("Bearbeiten");
menuBar.add(bearbeitenMenu);
JMenuItem menuItem = new JMenuItem("menuItem");
bearbeitenMenu.add(menuItem);
JTextArea textArea = new JTextArea("textArea");
bearbeitenMenu.add(new JScrollPane (textArea));
}
private void jtree_and_jsplitpane() {
JFrame jframe = new JFrame();
jframe.setJMenuBar(menuBar);
// Container container = new Container();
jframe.setResizable(false);
/* links */
JTree jtree = new JTree(createTree());
JPanel leftp = new JPanel();
JScrollPane treeView = new JScrollPane(jtree);
treeView.setPreferredSize(new Dimension(300, 800));
leftp.add(treeView);
/* rechts */
// jframe.setLayout(null);;
JPanel rightp = new JPanel();
/* rightp.setLayout(new FlowLayout());
JLabel jlabel1 = new JLabel();
rightp.add(jlabel1) ;
JButton jbutton1 = new JButton();
rightp.add(jbutton1);
// rightp.add();*/
/* FlowLayout fl = new FlowLayout();
rightp.setLayout(fl);
JButton jbutton1 = new JButton();
rightp.add(jbutton1);mn */
// JPanel xy = new JPanel();
// jPanel1.remove(xy);
/* JPanel jpanel_right = new JPanel();
rights(jpanel_right);
JPanel jpanel_rightY;
jpanel_rightY = rights(jpanel_right);
rightp.add(jpanel_rightY);*/
JLabel jlabel0 = new JLabel();
/* rights(jlabel0);*/
JPanel jpanel_rightY;
// JPanel jpanel_right = new JPanel();
jpanel_rightY = rights(jlabel0);
rightp.add(jpanel_rightY);
// Component jpanel1;
// rightp.add(jpanel_rightY);
/* splitpane */
// BorderLayout
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT) ;
splitPane.setLeftComponent(leftp);
splitPane.setRightComponent(rightp);
Dimension minimumSize= new Dimension(100, 50);
// rightp.setMinimumSize(minimumSize);
leftp.setMinimumSize(minimumSize);
splitPane.setDividerLocation(310);
splitPane.setPreferredSize(new Dimension(1000, 500));
jframe.getContentPane().add(splitPane);
/* UNTEN */
jframe.setTitle("Studafis II");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setLocationRelativeTo(null);
jframe.setSize(1920, 1080);
jframe.getMaximumSize();
jframe.setVisible(true);
}
// private JPanel rights(JPanel jpanel_right) {
private JPanel rights(JLabel jlabel0) {
String text = "GroupLayout2";
/* Grouplayout Anfang*/
if (text == "GroupLayout2") {
String[] spalte = {"Vorname", "Nachname", "Geburtstag", "Straße", "Hausnummer", "Postleitzahl", "Ort"};
Object[][] reihen = {{"Peter", "Fölix", "31.08.1971", "Ritter-Hundt-Straße", "32b", "55291", "Saulheim"},
{"Ruth", "Pommerenk", "08.12.1977", "Otto-Hahn-Straße", "8", "55291", "Saulheim"}};
JTable table = new JTable(reihen, spalte);
table.setPreferredScrollableViewportSize(new Dimension(450, 63));
table.setFillsViewportHeight(true);
JScrollPane jscrollPane_table = new JScrollPane();
jscrollPane_table.getViewport().add(table);
jpanel1.add(jscrollPane_table);
JLabel label = new JLabel("Label");
JTextField textField = new JTextField("TextField");
JCheckBox caseCheckBox = new JCheckBox("CheckBox case");
JCheckBox wholeCheckBox = new JCheckBox("CheckBox whole");
JCheckBox wrapCheckBox = new JCheckBox("CheckBox wrap");
JCheckBox backCheckBox = new JCheckBox("CheckBox back");
JButton findButton = new JButton("FindButton");
JButton cancelButton = new JButton("Cancel Button");
JButton button_add = new JButton("Hinzufügen");
JButton button_update = new JButton("Aktualisieren");
JButton button_abort = new JButton("beenden");
GroupLayout layout = new GroupLayout(jpanel1);
jpanel1.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(jscrollPane_table)
// .addComponent(button_add)
.addGroup(layout.createSequentialGroup()
.addComponent(button_add).addComponent(button_update))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) // SequentialGroup() //SequentialGroup()
.addComponent(label))
/* .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(label)
.addComponent(component)*/
/* .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(label))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(label))*/
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(textField)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(caseCheckBox)
.addComponent(wholeCheckBox))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(wrapCheckBox)
.addComponent(backCheckBox))))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(findButton)
.addComponent(cancelButton))
);
layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton);
layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(jscrollPane_table)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(button_add).addComponent(button_update))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label)
.addComponent(textField)
.addComponent(findButton))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(caseCheckBox)
.addComponent(wrapCheckBox))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(wholeCheckBox)
.addComponent(backCheckBox)))
.addComponent(cancelButton))
);
}
/* GroupLayout Ende */
return jpanel1;
}
private static TreeNode createTree(){
// TreeNodes mit String und Color-Objekten herstellen
DefaultMutableTreeNode root = new DefaultMutableTreeNode( "Studafis 2" );
// root.add(new DefaultMutableTreeNode("RIGHT"));
// root.add(new DefaultMutableTreeNode("LEFT"));
DefaultMutableTreeNode Tabellen = new DefaultMutableTreeNode( "Tabellen" );
DefaultMutableTreeNode green = new DefaultMutableTreeNode( "Grün" );
DefaultMutableTreeNode blue = new DefaultMutableTreeNode( "Blau" );
root.add( Tabellen );
root.add( green );
root.add( blue );
// for( float f = 0; f <= 1f; f += 0.05f )
// red.add( new DefaultMutableTreeNode( new Color( f, 0, 0 )));
// DefaultMutableTreeNode Tabellen1 = new DefaultMutableTreeNode("Tabellen");
Tabellen.add( new DefaultMutableTreeNode ( "frmAuszubildende"));
Tabellen.add( new DefaultMutableTreeNode ( "frmFirmen"));
Tabellen.add( new DefaultMutableTreeNode ( "frmPersonen"));
Tabellen.add( new DefaultMutableTreeNode ( "frmBereicheUndBerufe" ));
Tabellen.add( new DefaultMutableTreeNode ( "frmBerufslehrjahrVerantwortliche"));
Tabellen.add( new DefaultMutableTreeNode ( "frmBerufsschultermine"));
Tabellen.add( new DefaultMutableTreeNode ( "frmBerufsschultermine2"));
Tabellen.add( new DefaultMutableTreeNode ( "frmAusbildungsplatzangebote"));
Tabellen.add( new DefaultMutableTreeNode ( "frmAusbildungsplatzVerantwortliche"));
Tabellen.add( new DefaultMutableTreeNode ( "frmBeurteilungspunke"));
Tabellen.add( new DefaultMutableTreeNode ( "frmTaetigkeiten"));
Tabellen.add( new DefaultMutableTreeNode ( "frmSicherheitsunterweisungen"));
Tabellen.add( new DefaultMutableTreeNode ( "frmVerwaltungsMitteilungsformulare"));
Tabellen.add( new DefaultMutableTreeNode ( "frmAusbildungsplatzkatalog"));
Tabellen.add( new DefaultMutableTreeNode ( "frmTaetigkeitskatalog"));
Tabellen.add( new DefaultMutableTreeNode ( "frmSicherheitskatalog"));
Tabellen.add( new DefaultMutableTreeNode ( "frmPflichtausbildunsplaetze"));
Tabellen.add( new DefaultMutableTreeNode ( "frmVersetzung"));
Tabellen.add( new DefaultMutableTreeNode ( "frmVerwaltungsMitteilungen"));
Tabellen.add( new DefaultMutableTreeNode ( "frmVerwaltungsUebersichten"));
Tabellen.add( new DefaultMutableTreeNode ( "frmErfassungAusbildungsbericht"));
Tabellen.add( new DefaultMutableTreeNode ( "frmGesamtuebersicht"));
for( float f = 0; f <= 1f; f += 0.05f )
green.add( new DefaultMutableTreeNode( new Color( 0, f, 0 )));
for( float f = 0; f <= 1f; f += 0.05f )
blue.add( new DefaultMutableTreeNode( new Color( 0, 0, f )));
return root;
}
public void actionPerformed(ActionEvent event) {
// System.exit(0);
System.out.println("Selected: " + event.getActionCommand());
JFileChooser fc = new JFileChooser();
fc.showOpenDialog(null);
if (event.getSource() == "oeffnen") {
System.out.println(""
+ "öffnen");
}
else if (event.getSource() == openItem) {
System.exit(0);
}
else if (event.getSource() == "Schliessen") {
System.out.println("Schließen");
System.exit(0);
}
}
}
Ich will, das die Gruppe untereinander sein soll, und nicht links untreeinander.
Was mache ich falsch?
Peter