FlowLayout inside BorderLayout.NORTH

Hi all,

I have arranged multiple Buttons with FlowLayout in the NORTH position of a BorderLayout.

Now everytime I press one of the Buttons the FlowLayout is rearranged. The Buttons change their positions.

This behaviour is annoying. Is it a bug or a feature that FlowLayout changes itself at runtime?

This is the code snippet:

private javax.swing.JPanel getButtonBarPane(){

if (ivjButtonBarPane ==null){

try{

ivjButtonBarPane =new javax.swing.JPanel();

ivjButtonBarPane.setName("ButtonBarPane");

ivjButtonBarPane.setLayout(new java.awt.FlowLayout());

// user code begin {1}

// Buttons:

//JPanel south_panel = new JPanel();

// Select/Minimize-Button:

bSelectMin =new JButton("Select VCI & diag");

bSelectMin.setActionCommand("select");

bSelectMin.addActionListener(this);

//south_panel.add(bSelectMin);

//bSelectMin.setPreferredSize(new Dimension(200,100));//kein Effekt in BorderLayout

ivjButtonBarPane.add(bSelectMin);//, BorderLayout.LINE_START);//"North");

// Seek-Button

bSeekVCI =new JButton("Seek selected VCI");

bSeekVCI.setActionCommand("seekVCI");

bSeekVCI.addActionListener(this);

//south_panel.add(bSeekVCI);

ivjButtonBarPane.add(bSeekVCI);//, BorderLayout.LINE_START);//"North");

// Info-Button

bInfo =new JButton("Info");

bInfo.setActionCommand("info");

bInfo.addActionListener(this);

//south_panel.add(bInfo);

ivjButtonBarPane.add(bInfo);//, BorderLayout.CENTER);//"North");

}catch{...}

}

}

[2850 byte] By [gerrit.ledera] at [2007-11-26 14:24:35]
# 1
Post a Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the problem. http://mindprod.com/jgloss/sscce.html
Rodney_McKaya at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 2

[nobr]package flowLayout;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.Button;

import java.awt.Choice;

import java.awt.Dimension;

import java.awt.Font;

import java.awt.Frame;

import java.awt.Image;

import java.awt.Label;

import java.awt.List;

import java.awt.Panel;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import javax.swing.ImageIcon;

//import VciManagement;

//import VciManagement.VciMgmVersions;

//Statusleiste:

import java.awt.*;

import javax.swing.*;

import javax.swing.JLabel;

public class MainFrm extends JFrame

implements WindowListener, ActionListener

{

int iWidth = 700;

private boolean bSelectHandled = true;

private boolean bBuzzerHandled = true;

private boolean bExitHandled = true;

private List lst;

public static JButton bSelectMin;

private JButton bSeekVCI;

private JButton bInfo;

private Choice chChannelSelect;

private JLabel lbChannel;

private int iButtonWidth;

// public InfoFrm infoFrm;

//public static InfoFrame infoFrm;

private int channel;

private VciManagement vciMgm;

private Image image;

private ImageIcon imageicon; //for ClassLoader

//Statusleiste, Buttonleiste und JLabel:

private JPanel ivjStatusBarPane = null;

private JPanel ivjButtonBarPane = null;

//private JMenuItem ivjStatusleisteMenuItem = null;

private JLabel ivjStatusMsg1 = null;

private JLabel ivjStatusMsg2 = null;

private JPanel ivjJFrameContentPane = null;

private JLabel description = null;

private int iCnt=0;

public static class ListEntry {

public String logicalName;

public int workingState;

public String tester;

public String application;

public long lastUsed;

public boolean selected;

//Datenbankmanagement + List/JTable:

public String RealStation;

public String RealUser;

public int sessionid;

public static boolean cmpListEntries(ListEntry entry1, ListEntry entry2){

if ((entry1.logicalName != null) && (entry2.logicalName != null)) {

return (entry1.logicalName.toString().matches(entry2.logicalName.toString()));

} else {

return false;

}

}

}

public void fillList(ListEntry[] list_entries){

String highlighted_item = "";

if ( lst.getSelectedIndex() >= 0 || lst.getSelectedIndex() <= lst.getItemCount()) {

highlighted_item = lst.getSelectedItem();

if (highlighted_item == null){

highlighted_item = "";

}

}

lst.removeAll();

for (int cnt = 0; cnt < list_entries.length; cnt++) {

String new_entry = list_entries[cnt].logicalName + " - "

//+ list_entries[cnt].workingState + " - "

+ list_entries[cnt].tester + " - "

+ list_entries[cnt].application + " - "

//+ list_entries[cnt].lastUsed + " - "

//+ list_entries[cnt].selected + " - "

+ list_entries[cnt].RealStation + " - "

+ list_entries[cnt].RealUser + " - "

+ list_entries[cnt].sessionid;

lst.add(new_entry);

/*if (iCnt==0) {

//JLabel jlabel = jlst.getListCellRendererComponent(...);//nur Swing

lst.setForeground(VciManagement.color0);//TODO: Farbe nach vci_id logicalname

iCnt++;

} else

if (iCnt==1) {

lst.setForeground(VciManagement.color1);//TODO: Farbe nach vci_id logicalname

iCnt++;

} else

if (iCnt==2) {

lst.setForeground(VciManagement.color2);//TODO: Farbe nach vci_id logicalname

iCnt++;

} else

if (iCnt==3) {

lst.setForeground(VciManagement.color3);//TODO: Farbe nach vci_id logicalname

iCnt++;

}

*/

if (highlighted_item.split(" - ")[0].matches(list_entries[cnt].logicalName)){

lst.select(cnt);

}

}

//if (infoFrm != null) {

//infoFrm.updateInfoFrame("Schloss_geschlossen.gif", getSelectedItem().logicalName);

//}

}

public ListEntry getSelectedItem( ){

ListEntry lstEntry = new ListEntry();

if ( lst.getSelectedIndex() < 0 || lst.getSelectedIndex() >= lst.getItemCount()) {

// MsgBoxes Warning = new MsgBoxes();

// Warning.WarningBox("No VCI selected!");

} else {

lstEntry.logicalName = lst.getSelectedItem().split(" - ")[0];

}

return lstEntry;

}

/**

* Method to read environment variable of windows-os.<BR>

*

* <TABLE>

* <TR><TH WIDTH = 60, ALIGN=left>Input:</TH><TH WIDTH = 130, ALIGN=left><TH WIDTH = 20></TH></TH></TR>

* <TR><TD></TD><TD>String EnvVar</TD><TD>:</TD><TD>Name of environment variable to be read.</TD></TR>

* </TABLE>

*

* <TABLE>

* <TR><TH WIDTH = 60, ALIGN=left>Output:</TH><TH WIDTH = 130, ALIGN=left></TH></TR>

* <TR><TD></TD><TD>String</TD><TD>Content of analysed environmnet variable.</TD></TR>

* </TABLE>

*

* <TABLE>

* <TR><TH WIDTH = 60, ALIGN=left>History:</TH><TH WIDTH = 70, ALIGN=left></TH><TH WIDTH = 70, ALIGN=left></TH><TH WIDTH = 30, ALIGN=left></TH></TR>

* <!-- Hist-Entry: VERSIONDATENAME COMMENT -->

* <TR><TD></TD><TD>00.00.00</TD><TD>27/06/06</TD><TD>JF</TD><TD>Creation</TD></TR>

*</TABLE>

**/

private String ReadEnvVar(String EnvVar){

// TODO replace by String test2 = new String(System.getenv("sessionname"));

String sRet = new String("");

try {

Process p = Runtime.getRuntime().exec( "cmd /c echo %" + EnvVar + "%");

p.waitFor();

BufferedReader in = new BufferedReader(

new InputStreamReader(p.getInputStream())

);

for ( String s; (s = in.readLine()) != null; ) {

sRet = s;

System.out.println( s );

}

// @TODO check exeptions:

} catch ( IOException ioe ) {

System.err.println( "IO error: " + ioe );

} catch ( InterruptedException ie ) {

System.err.println( ie );

}

return (sRet);

}

public MainFrm(VciManagement vciMgm, int channel){

this.vciMgm = vciMgm;

this.channel = channel;

// Title:

setTitle("VCI Toolkit for " + ReadEnvVar("COMPUTERNAME") + " and session = " +ReadEnvVar("SESSIONNAME"));

setResizable(false);

//setDefaultLookAndFeelDecorated(true);

//imageicon = new ImageIcon(getClass().getClassLoader().getResource("resources/tzm.gif"));

//image = imageicon.getImage();

//setIconImage( image );//OK in Jar

//setIconImage( Toolkit.getDefaultToolkit().getImage( "resources/tzm.gif" ) );//?not OK in Jar

setSize(iWidth, 300);

disableEvents(WindowEvent.WINDOW_ICONIFIED);

/*// Info:

lst = new List(4, false);

lst.setMultipleMode(false);

lst.setFont(new Font("Courier New", Font.PLAIN, 12));

add(lst);

// Buttons:

JPanel south_panel = new JPanel();

// Select/Minimize-Button:

bSelectMin = new JButton("Select VCI start diag");

bSelectMin.setActionCommand("select");

bSelectMin.addActionListener(this);

south_panel.add(bSelectMin);

// Seek-Button

bSeekVCI = new JButton("Seek selected VCI");

bSeekVCI.setActionCommand("seekVCI");

bSeekVCI.addActionListener(this);

south_panel.add(bSeekVCI);

// Info-Button

bInfo = new JButton("Info");

bInfo.setActionCommand("info");

bInfo.addActionListener(this);

south_panel.add(bInfo);

// Channel-Select:

chChannelSelect = new Choice();

lbChannel = new JLabel("Channel: ");

lbChannel.setAlignment(JLabel.RIGHT);

for (int channelNo = 0; channelNo < VciManagement.getNoSuppChannels(); channelNo++) {

chChannelSelect.add(String.valueOf(channelNo));

}

chChannelSelect.select(this.channel);

chChannelSelect.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

if (e.getStateChange() == ItemEvent.SELECTED) {

System.out.println("channel = >" + chChannelSelect.getSelectedItem() + "<");

}

}

});

south_panel.add(lbChannel);

south_panel.add(chChannelSelect);

add(south_panel, BorderLayout.SOUTH);

*/

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

setLocation( (d.width - getSize().width) / 2,

(d.height - getSize().height) / 2 );

//Statusleiste:

initialize();

//setContentPane(getJFrameContentPane());

//south_panel.add(getJFrameContentPane());

/*try {

// user code begin {1}

// user code end

this.viewStatusBar();

// user code begin {2}

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {3}

// user code end

handleException(ivjExc);

}

*///

//infoFrm = new InfoFrame(this);

addWindowListener( this );

}

// ************************ Implements WindowListener **********************

public void windowClosing( WindowEvent event ) {

if (MsgBoxes.YesNoBox(this, "Are you sure to exit complete diagnosis-session?")) {

setExitHandled(false);

//vciMgm.interrupt();

// dispose();

//} else {//DEBUG

//No Button: setVisible=true

//setVisible(true);

}//if

}

public void windowClosed( WindowEvent event ) {}//setVisible(true);}

public void windowDeiconified( WindowEvent event ) {}

public void windowIconified( WindowEvent event ) {

if ( lst.getSelectedIndex() < 0 || lst.getSelectedIndex() >= lst.getItemCount()) {

setExtendedState(Frame.NORMAL);

MsgBoxes.WarningBox(this, "No VCI highlighted! - TODO: should be selected!");

} else {

setVisible(false);

//infoFrm.setVisible(true);

}

}

public void windowActivated( WindowEvent event ) {

int iSpaceBetween = 5;

int iNoOfButtons = 4;

iButtonWidth = (iWidth - iSpaceBetween * (iNoOfButtons - 1) - 30) / iNoOfButtons;

bSelectMin.setBounds(15, 0, iButtonWidth, 30);

bSeekVCI.setBounds(15 + 1 * (iButtonWidth + iSpaceBetween), 0, iButtonWidth, 30);

bInfo.setBounds (15 + 2 * (iButtonWidth + iSpaceBetween), 0, iButtonWidth, 30);

lbChannel.setBounds(15 + 3 * (iButtonWidth + iSpaceBetween), 0, (iButtonWidth/3) * 2, 30);

chChannelSelect.setBounds(15 + 3 * (iButtonWidth + iSpaceBetween) + (iButtonWidth/3) * 2, 0, iButtonWidth/3, 30);

}

public void windowDeactivated( WindowEvent event ) {

System.out.println(">windowDeactivated<");

}

public void windowOpened( WindowEvent event ) {}

// *************************************************************************

// ************************ Implements EventListener ***********************

public void actionPerformed(ActionEvent arg0) {

String cmd = arg0.getActionCommand();

// @TODO remove following text-block:

if(cmd.equals("end")) {

//setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

dispose();

System.exit(0);

}

if(cmd.equals("seekVCI")) {

setBuzzerHandled(false);

//vciMgm.interrupt();

return;

}

if(cmd.equals("select")) {

setSelectHandled(false);

if (bSelectHandled==true) bSelectMin.setLabel("Select VCI & diag");

else bSelectMin.setLabel("Select/Minimize");

//vciMgm.interrupt();

return;

}

if(cmd.equals("info")) {

//VciMgmVersions versions = VciManagement.getTsToolkitVersions();

// @TODO check for tabulator \t

String message = "Toolkit to manage vehicle communication interfaces on a terminal server.";

message +="\n\nVersion-Infos:";

//message +="\nVCI-Toolkit:" + versions.toolkit;

//message +="\nSD_DCDI_ToolkitAPI_JNI_Wrapper.dll lokal:" + versions.toolkitApiJniWrapper;

//message +="\nSD_DCDI_ToolkitAPI_JNI_Wrapper.dll Param.: " + versions.jniWrapper;

//message +="\nSDDCDI1.exe:" + versions.sddcdi1Exe;

//message +="\nLaunchComServer.exe: " + versions.launchComServerExe;

MsgBoxes.InfoBox(this, message);

return;

}

}

// *************************************************************************

public int getChannel() {

channel = Integer.parseInt(chChannelSelect.getSelectedItem());

return channel;

}

public boolean isSelectHandled() {

return bSelectHandled;

}

public boolean isBuzzerHandled() {

return bBuzzerHandled;

}

public void setSelectHandled(boolean state) {

bSelectHandled = state;

}

public void setBuzzerHandled(boolean state) {

bBuzzerHandled = state;

}

public boolean isExitHandled() {

return bExitHandled;

}

public void setExitHandled(boolean exitHandled) {

bExitHandled = exitHandled;

}

/**

* Den Eigenschaftswert StatusBarPane zur點kgeben.

* @return javax.swing.JPanel

*/

/* WARNUNG: DIESE METHODE WIRD ERNEUT GENERIERT. */

private javax.swing.JPanel getStatusBarPane() {

if (ivjStatusBarPane == null) {

try {

ivjStatusBarPane = new javax.swing.JPanel();

ivjStatusBarPane.setName("StatusBarPane");

ivjStatusBarPane.setLayout(new java.awt.BorderLayout());

ivjStatusBarPane.add(getStatusMsg1(), "West");

ivjStatusBarPane.add(getStatusMsg2(), "Center");

// user code begin {1}

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {2}

// user code end

handleException(ivjExc);

}

}

return ivjStatusBarPane;

}

private javax.swing.JPanel getButtonBarPane() {

if (ivjButtonBarPane == null) {

try {

ivjButtonBarPane = new javax.swing.JPanel();

ivjButtonBarPane.setName("ButtonBarPane");

ivjButtonBarPane.setLayout(new java.awt.FlowLayout());

// user code begin {1}

// Buttons:

//JPanel south_panel = new JPanel();

// Select/Minimize-Button:

bSelectMin = new JButton("Select VCI & diag");

bSelectMin.setActionCommand("select");

bSelectMin.addActionListener(this);

//south_panel.add(bSelectMin);

//bSelectMin.setPreferredSize(new Dimension(200,100));//kein Effekt in BorderLayout

ivjButtonBarPane.add(bSelectMin);//, BorderLayout.LINE_START);//"North");

// Seek-Button

bSeekVCI = new JButton("Seek selected VCI");

bSeekVCI.setActionCommand("seekVCI");

bSeekVCI.addActionListener(this);

//south_panel.add(bSeekVCI);

ivjButtonBarPane.add(bSeekVCI);//, BorderLayout.LINE_START);//"North");

// Info-Button

bInfo = new JButton("Info");

bInfo.setActionCommand("info");

bInfo.addActionListener(this);

//south_panel.add(bInfo);

ivjButtonBarPane.add(bInfo);//, BorderLayout.CENTER);//"North");

//////////////////////////////////////// Channel-Select:

chChannelSelect = new Choice();

lbChannel = new JLabel("Channel: ", JLabel.RIGHT);

lbChannel.setName("channel");

//lbChannel.setBorder(new javax.swing.border.EtchedBorder());

lbChannel.setText("Channel: ");

//lbChannel.setAlignment(JLabel.RIGHT);

//for (int channelNo = 0; channelNo < VciManagement.getNoSuppChannels(); channelNo++) {

//chChannelSelect.add(String.valueOf(channelNo));

//}

/*chChannelSelect.select(this.channel);

chChannelSelect.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

if (e.getStateChange() == ItemEvent.SELECTED) {

System.out.println("channel = >" + chChannelSelect.getSelectedItem() + "<");

}

}

});

*///south_panel.add(lbChannel);

//south_panel.add(chChannelSelect);

/*ivjButtonBarPane.add(lbChannel);//, BorderLayout.LINE_END);//"North");

ivjButtonBarPane.add(chChannelSelect);//, BorderLayout.LINE_END);//"North");

*///////////////////TODO: Channel working with DAS and Buttons (North)

/*description = new JLabel ();//"VCI - Tester - Application - Station - User - Session", JLabel.LEFT);

description.setName("description");

description.setBorder(new javax.swing.border.EtchedBorder());

description.setText("VCI - Tester - Application - Station - User - Session");

ivjButtonBarPane.add(description);

*/ivjButtonBarPane.validate();

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {2}

// user code end

handleException(ivjExc);

}

}

return ivjButtonBarPane;

}

/**

* Den Eigenschaftswert StatusMsg1 zur點kgeben.

* @return javax.swing.JLabel

*/

/* WARNUNG: DIESE METHODE WIRD ERNEUT GENERIERT. */

private javax.swing.JLabel getStatusMsg1() {

if (ivjStatusMsg1 == null) {

try {

ivjStatusMsg1 = new javax.swing.JLabel();

ivjStatusMsg1.setName("StatusMsg1");

ivjStatusMsg1.setBorder(new javax.swing.border.EtchedBorder());

ivjStatusMsg1.setText("Message: ");

// user code begin {1}

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {2}

// user code end

handleException(ivjExc);

}

}

return ivjStatusMsg1;

}

/**

* Den Eigenschaftswert StatusMsg2 zur點kgeben.

* @return javax.swing.JLabel

*/

/* WARNUNG: DIESE METHODE WIRD ERNEUT GENERIERT. */

public javax.swing.JLabel getStatusMsg2() {

if (ivjStatusMsg2 == null) {

try {

ivjStatusMsg2 = new javax.swing.JLabel();

ivjStatusMsg2.setName("StatusMsg2");

ivjStatusMsg2.setBorder(new javax.swing.border.EtchedBorder());

ivjStatusMsg2.setText("");

// user code begin {1}

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {2}

// user code end

handleException(ivjExc);

}

}

return ivjStatusMsg2;

}

/**

* Den Eigenschaftswert JFrameContentPane zur點kgeben.

* @return javax.swing.JPanel

*/

/* WARNUNG: DIESE METHODE WIRD ERNEUT GENERIERT. */

private javax.swing.JPanel getJFrameContentPane() {

if (ivjJFrameContentPane == null) {

try {

ivjJFrameContentPane = new javax.swing.JPanel();

ivjJFrameContentPane.setName("JFrameContentPane");

ivjJFrameContentPane.setLayout(new java.awt.BorderLayout(5,5));

//getJFrameContentPane().add(getToolBarPane(), "North");

//"South");

//getJFrameContentPane().add(getWstartPane(), "Center");

// user code begin {1}

// Info:

ivjJFrameContentPane.add(getButtonBarPane(), BorderLayout.PAGE_START);//"Center");

viewButtonBar();

lst = new List(4, false);

lst.setMultipleMode(false);

lst.setFont(new Font("Courier New", Font.PLAIN, 22));

//add(lst);

//getJFrameContentPane().add(lst, "Center");

ivjJFrameContentPane.add(lst, BorderLayout.CENTER);//"Center");

lst.setVisible(true);

//add(south_panel, BorderLayout.SOUTH);

//getJFrameContentPane().add(south_panel, BorderLayout.SOUTH);

ivjJFrameContentPane.add(getStatusBarPane(), BorderLayout.PAGE_END);

viewStatusBar();

// user code end

} catch (java.lang.Throwable ivjExc) {

// user code begin {2}

// user code end

handleException(ivjExc);

}

}

return ivjJFrameContentPane;

}

public void viewStatusBar() {

/* Statusleiste ein- oder ausblenden */

//getStatusBarPane().setVisible(!(getStatusBarPane().isVisible()));

getStatusBarPane().setVisible(true);

}

public void viewButtonBar() {

/* Statusleiste ein- oder ausblenden */

//getStatusBarPane().setVisible(!(getStatusBarPane().isVisible()));

getButtonBarPane().setVisible(true);

}

private void initialize() {

try {

// user code begin {1}

// user code end

//setName("Wstart");

//setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

//setJMenuBar(getWstartJMenuBar());

//setSize(645, 483);

//setTitle("Wstart");

/*setSize(iWidth, 300);

disableEvents(WindowEvent.WINDOW_ICONIFIED);

*/

setContentPane(getJFrameContentPane());

getJFrameContentPane().setVisible(true);

//initConnections();

} catch (java.lang.Throwable ivjExc) {

handleException(ivjExc);

}

// user code begin {2}

// user code end

}

/**

* Wird aufgerufen, wenn die Komponente eine Ausnahmebedingung 黚ergibt.

* @param exception java.lang.Throwable

*/

private void handleException(java.lang.Throwable exception) {

/* Entfernen Sie den Kommentar f黵 die folgenden Zeilen, um nicht abgefangene Ausnahmebedingungen auf der Standardausgabeeinheit (stdout) auszugeben */

System.out.println(" NICHT ABGEFANGENE AUSNAHMEBEDINGUNG ");

exception.printStackTrace(System.out);

}

}

[/nobr]

gerrit.ledera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 3

package flowLayout;

import java.awt.Frame;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.beans.PropertyChangeEvent;

import java.beans.PropertyChangeListener;

import javax.swing.ImageIcon;

import javax.swing.JDialog;

import javax.swing.JOptionPane;

//import javax.swing.ImageIcon;

/**

* Tests and shows how to use MessageBox.

*

* @author Jack Harich

*/

public class MsgBoxes {

//- Initialization

public MsgBoxes() {

}

/** Returns an ImageIcon, or null if the path was invalid. */

private static ImageIcon createImageIcon(String path) {

java.net.URL imgURL = MsgBoxes.class.getResource(path);

if (imgURL != null) {

return new ImageIcon(imgURL);

} else {

System.err.println("Couldn't find file: " + path);

return null;

}

}

public static boolean YesNoBox_Alt(Frame parentfrm, String msg) {

// JOptionPane pane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE);

int n = JOptionPane.showConfirmDialog(

parentfrm, msg,

"Question",

JOptionPane.YES_NO_OPTION);

if (n == JOptionPane.YES_OPTION) {

return true;

} else {

return false;

}

}

public static boolean YesNoBox(Frame parentfrm, String msg) {

boolean ret_val = false;

final JOptionPane optionPane = new JOptionPane(msg, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

//You can't use pane.createDialog() because that

//method sets up the JDialog with a property change

//listener that automatically closes the window

//when a button is clicked.

final JDialog dialog = new JDialog(parentfrm, "Question", true);

dialog.setContentPane(optionPane);

dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

dialog.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) { }

});

optionPane.addPropertyChangeListener(

new PropertyChangeListener() {

public void propertyChange(PropertyChangeEvent e) {

String prop = e.getPropertyName();

if (dialog.isVisible()

&& (e.getSource() == optionPane)

&& (JOptionPane.VALUE_PROPERTY.equals(prop))) {

//If you were going to check something

//before closing the window, you'd do

//it here.

dialog.setVisible(false);

}

}

});

dialog.pack();

dialog.setLocationRelativeTo(parentfrm);

dialog.setVisible(true);

int value = ((Integer)optionPane.getValue()).intValue();

if (value == JOptionPane.YES_OPTION) {

ret_val = true;

} else if (value == JOptionPane.NO_OPTION) {

ret_val = false;

} else {

ret_val = false;

}

return ret_val;

}

public static void WarningBox(Frame parentfrm, String msg) {

JOptionPane pane = new JOptionPane(msg, JOptionPane.WARNING_MESSAGE);

ImageIcon icon = createImageIcon("resources/LightBulb.gif");

pane.setIcon(icon);

pane.createDialog(parentfrm, "Warning").setVisible(true );

}

public static void ErrorBox(Frame parentfrm, String msg) {

JOptionPane pane = new JOptionPane(msg, JOptionPane.ERROR_MESSAGE );

pane.createDialog(parentfrm, "Error").setVisible(true );

}

public static void InfoBox(Frame parentfrm, String msg) {

JOptionPane pane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE);

// ImageIcon icon = createImageIcon("LightBulb.gif");

// pane.setIcon(icon);

pane.createDialog(parentfrm, "Information").setVisible(true );

//pane.set.Xxxx(...); // Configure

/*

Object selectedValue = pane.getValue();

System.out.println("selectedValue: " + selectedValue.toString());

*/

}

} // End class

gerrit.ledera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 4

package flowLayout;

//import MainFrm;

//import VciManagement;

//import MainFrm;

public class VciManagement {

private static MainFrm mainFrm;

public VciManagement(boolean Debug) {

Boolean bDebug = Debug;

mainFrm = new MainFrm(this, 1);

mainFrm.setVisible(true);

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

VciManagement vciMgm = new VciManagement(true);

}

}

gerrit.ledera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 5
I guess you didn't understand what does SSCCE means.This is LSCCE (Long) and I don't even know about the rest since I will not even try to read it.Read again. http://homepage1.nifty.com/algafield/sscce.html
Rodney_McKaya at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 6

Hi there,

I have RTFM. Then I have supplied a code "snippet". Then I have supplied, as requested, compilable classes.

Please have yourself a look at the gui. Press Info Button. Press OK.

And then I would like to know if the behaviour is a bug or a feature.

I know, that I have no stripped to the bones error report, but on the other hand I have not reported an error!

Bye

Gerrit

gerrit.ledera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 7

I haven't read all your code, but I can tell you that nothing in BorderLayout or FlowLayout causes the layout to be rearranged when a button is pressed, so it must be your code. Perhaps your ActionListener is doing something that influences the layout. Also, I notice that you seem to be setting the bounds of your buttons each time the window is activated, which is a weird and wasteful thing to be doing, I think...

Geoff

glevnera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 8

I cannot compile your class MainFrm because there are other classes missing.

I use often Buttons in one Panel added to the SOUTH of BorderLayout and no position changing happens when I click them. So there must be something wrong with your code. To find out you should write a small program that is working and then add more and more complexity. You will see what causes the weird behaviour. No one here will read through your code, if it is so long and not compilable.

Annette

Annettea at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 9
Sorry, I have seen you posted the missing classes. Nevertheless, it is too long. I am sure you will find the mistake easily when you shorten your main-class. FlowLayout and BorderLayout work fine!Good luck!Annette
Annettea at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...
# 10

> I haven't read all your code, but I can tell you that

> nothing in BorderLayout or FlowLayout causes the

> layout to be rearranged when a button is pressed, so

> it must be your code. Perhaps your ActionListener is

> doing something that influences the layout. Also, I

> notice that you seem to be setting the bounds of your

> buttons each time the window is activated, which is a

> weird and wasteful thing to be doing, I think...

>

> Geoff

Thanks to all,

the problem was the setting of the button bounds, when the window is activated.

Changed that, now the FlowLayout is stable.

Gerrit

gerrit.ledera at 2007-7-8 2:17:18 > top of Java-index,Desktop,Core GUI APIs...