Code:
package testapp;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Color;
import java.awt.Cursor;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JButton;
import java.awt.FlowLayout;
import javax.swing.JScrollPane;
public class BorderTest extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
public int mainframe_x=0;
public int mainframe_y=0;
private JPanel jPanelSouth = null;
private JLabel jLabelS = null;
private JButton jButtonLogin = null;
private JButton jButtonLogout = null;
private JPanel jPanelLogin = null;
private JPanel jPanelNorth = null;
private JScrollPane jScrollPaneEigenschaften = null;
private JScrollPane jScrollPaneBild = null;
private JLabel jLabelE = null;
private JLabel jLabelW = null;
private JButton jButton3 = null;
/**
* This is the default constructor
*/
public BorderTest() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.mainframe_x=this.getGraphicsConfiguration().getBounds().width;
this.mainframe_y=this.getGraphicsConfiguration().getBounds().height;
this.setBounds(new Rectangle(0, 0, this.mainframe_x, this.mainframe_y));
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanelSouth(), BorderLayout.SOUTH);
jContentPane.add(getJPanelLogin(), BorderLayout.CENTER);
jContentPane.add(getJPanelNorth(), BorderLayout.NORTH);
jContentPane.add(getJScrollPaneBild(), BorderLayout.WEST);
jContentPane.add(getJScrollPaneEigenschaften(), BorderLayout.EAST);
}
return jContentPane;
}
/**
* This method initializes jPanelSouth
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelSouth() {
if (jPanelSouth == null) {
jLabelS = new JLabel();
jLabelS.setText("JLabel");
jPanelSouth = new JPanel();
jPanelSouth.setLayout(new GridBagLayout());
jPanelSouth.setBackground(Color.green);
jPanelSouth.add(jLabelS, new GridBagConstraints());
}
return jPanelSouth;
}
/**
* This method initializes jButtonLogin
*
* @return javax.swing.JButton
*/
private JButton getJButtonLogin() {
if (jButtonLogin == null) {
jButtonLogin = new JButton();
jButtonLogin.setText("LI");
jButtonLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jScrollPaneBild.setVisible(false);
jScrollPaneEigenschaften.setVisible(false);
jPanelLogin.setVisible(true);
}
});
}
return jButtonLogin;
}
/**
* This method initializes jPanelNorth
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelNorth() {
if (jPanelNorth == null) {
jPanelNorth = new JPanel();
jPanelNorth.setLayout(new FlowLayout());
jPanelNorth.add(getJButtonLogin(), null);
jPanelNorth.add(getJButtonLogout(), null);
jPanelNorth.add(getJButton3(), null);
}
return jPanelNorth;
}
/**
* This method initializes jScrollPaneEigenschaften
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPaneEigenschaften() {
if (jScrollPaneEigenschaften == null) {
jLabelE = new JLabel();
float x_f=(this.getGraphicsConfiguration().getBounds().width)*(1.0f/4.0f);
int x=Math.round(x_f);
jLabelE.setPreferredSize(new Dimension(x, 1));
jScrollPaneEigenschaften = new JScrollPane();
jScrollPaneEigenschaften.setViewportView(jLabelE);
jScrollPaneEigenschaften.setVisible(false);
}
return jScrollPaneEigenschaften;
}
/**
* This method initializes jScrollPaneBild
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPaneBild() {
if (jScrollPaneBild == null) {
System.out.println("test");
jLabelW = new JLabel();
float x_f=(this.getGraphicsConfiguration().getBounds().width)*(3.0f/4.0f);
int x=Math.round(x_f);
jLabelW.setPreferredSize(new Dimension(x, 1));
jScrollPaneBild = new JScrollPane();
jScrollPaneBild.setViewportView(jLabelW);
jScrollPaneBild.setVisible(false);
}
return jScrollPaneBild;
}
/**
* This method initializes jButtonLogout
*
* @return javax.swing.JButton
*/
private JButton getJButtonLogout() {
if (jButtonLogout == null) {
jButtonLogout = new JButton();
jButtonLogout.setText("1");
jButtonLogout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jScrollPaneBild.setVisible(true);
jPanelLogin.setVisible(false);
}
});
}
return jButtonLogout;
}
/**
* This method initializes jPanelLogin
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelLogin() {
if (jPanelLogin == null) {
jPanelLogin = new JPanel();
jPanelLogin.setLayout(new GridBagLayout());
jPanelLogin.setBackground(Color.yellow);
jPanelLogin.setVisible(false);
}
return jPanelLogin;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setText("2");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jPanelLogin.setVisible(false);
jScrollPaneEigenschaften.setVisible(true);
}
});
}
return jButton3;
}
} // @jve:decl-index=0:visual-constraint="4,4"
hi
so hab hier nen programm geschrieben das mir bei meinem layout problem weiterhelfen soll..
leider ist bei dem programm ein kleines problem aufgetreten das ich so net versteh...
also folgender effekt:
Variante 1:
- ich starte das programm
- drücke den button LI
--> alles ok es wird das gelbe panel angezeigt
Variante 2:
- ich starte das programm
- drücke den button 1
--> nichts passiert
Variante 3:
- ich starte das programm
- drücke den button 2
--> nichts passiert
Variante 4:
- ich starte das programm
- drücke den button LI
- drücke den button 1
- drücke den button 2
--> Gelbe Feld ok -> Linke Feld ok -> Rechte Feld wird nicht angezeigt
Variante 5:
- ich starte das programm
- drücke den button LI
- drücke den button 2
- drücke den button LI
- drücke den button 1
- drücke den button 2
--> nur so werden alle angezeigt...
Wenn ich bei variante 2 und 3 jedoch das fenster runter klappe und wiederhoch werden meine scrollpanels angezeigt... also dachte ich es liegt viellicht am repaint und hab nach jedem buttondruck auch ein repaint der einzelnen panels eingebaut -> kein effekt...
wieso ist das so?
und was kann ich gegen tun?
thx Kala