• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Screen meshing into main screen

 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[size=12] [/size]
Hi All,

I have an issue in Swing Application Screen .I have main screen and pop up screen when user closes the pop up screen it merges into main screen . it occurs only to specific users at random time .
Technologies used Swing .

I need a solution if there is any other way to close the screen.

Thank You
Vijay



 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With "merges" and "meshes" I'm assuming you mean that the popup's contents are drawn inside the main screen? If that's so, it appears to be a repainting issue. The Event Dispatcher Thread is probably repainting the user interface non-stop. This is often caused by programming mistakes, like causing a repaint inside the painting methods.
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

PF Source Code for the screen .
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe all your problems are caused by method getBrowserRecords. This method is performing database queries. These can take quite some time, and because you're performing them on the Event Dispatcher Thread this will cause freezes in the user interface and bad painting until the queries are finished. Read Concurrency in Swing for more information.
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thank you for your inputs . I did make chages accordingly but issue still persists in user Testing . please find the below chages in code . suggest any approach required .

 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please UseCodeTags next time? I've added them for twice already.

Also, it's time you create an SSCCE click on the acronym from this code, as it's really hard to see the problem in 800+ lines.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also restrict the lengths of your lines; I had to divide line 531 into 4, only to find the indentation is a mess because you have used tabs instead of spaces to indent. Use a bit of whitespace; lots of code with no breaks after commas is very difficult to read.
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,Campbell

will update the post with required changes,
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob & Campbell

PF source Code with comments .

The following is the Parent dialog (Cash Order screen)code which will open the child dialog (Customer search browser screen) on f4 key press


public class CashOrder extends UIDialog {

//instance variable declarations for dialog components
private UITextField itxtCustomer;

// Constructor which sets the parent frame
public CashOrder(UIFrame pParentFrame) {

//calling super class constructor passing the instance of parent frame
super(pParentFrame);

//initializing the instance variables
itxtCustomer = null;

}//end construtor

//getter method which returns the instance of textfield
public UITextField gettxtCustomer() {
if (itxtCustomer == null) {
//Setting the upper case document
UpperCase uppercase = new UpperCase();
uppercase.setSize(10);
itxtCustomer = new UITextField(uppercase, null, 0);
itxtCustomer.setName("txtCustomer");
itxtCustomer.setBounds(90, 59, 100, 20);

//adding key listner
itxtCustomer.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent pKeyEvent) {
int keyCode = pKeyEvent.getKeyCode();
int modifiers = pKeyEvent.getModifiers();
focus = true;

//on f4 key
if((modifiers!=1 || keyCode!=115)&& pKeyEvent.getKeyCode()==115 && pKeyEvent.getSource() == itxtCustomer) {
focus = false;
//this method opens the child dialog
callCustomerBrowser();
if(Common.isBlank(gettxtCustomer().getText())){
gettxtCustomer().grabFocus();
return;
}//end if
setHeaderData();
focus = true;
gettxtAddressNumber().requestFocusInWindow();
}//end if
//on enter
if (pKeyEvent.getKeyCode() == 10)
if (checkCustomer()) {
gettxtAddressNumber().grabFocus();
setHeaderData();
}//end if
}//end of keyPressed
});//end of addKeyListener

//adding focus listner
itxtCustomer.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {
if(gettxtCustomer().isEditable())
{
if(focus)
{
if (checkCustomer()) {
//gettxtAddressNumber().grabFocus();
setHeaderData();
}else{
focus = false;
}
}
}
}
});
}
return itxtCustomer;
}//end of gettxtCustomer

/*** This method opens the customer search browser upon pressing F4 in the Cash Order Screen on the Customer Number Field.
public void callCustomerBrowser() {
//refer below CustomerBrowser class
CustomerBrowser custBrowser = new CustomerBrowser(this);
custBrowser.setFrameOwner(this);
custBrowser.setSearchValue(gettxtCustomer().getText());
custBrowser.setIFlag(iFlag);
custBrowser.setCustOrdType1(getCustOrderType1());
custBrowser.setCustOrdType2(getCustOrderType2());
custBrowser.initialize(itxtCustomer.getText().trim());
}//end of callCustomerBrowser
}//end of class




The following is the child dialog (Customer search browser screen)code which is opened from Parent dialog (Cash Order screen)on f4 key press

public class CustomerBrowser extends UIDialog {


public CustomerBrowser(UIDialog pDialog) {
//pDialog is CashOrder instance
super(pDialog, true);
}

//This method retuns the instance of select button
public UIButton getbtnOK() {
if (ibtnOK == null) {
ibtnOK = new UIButton();
ibtnOK.setName("btnOK");
ibtnOK.setText("Select");
ibtnOK.setBounds(570, 200, 80, 25);
ibtnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onOK();
}
});
ibtnOK.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent pKeyEvent) {
doEvents(pKeyEvent);
}
});
}
return ibtnOK;
}


public UIDialog getFrameOwner() {
return iFrame;
}


//This method disposes the dialog when cancel button is clicked
public void onCancel() {
dispose();
}

//this method is called when select button is pressed
//this is where this screen merges in to the parent screen (CashOrder screen)
public void onOK() {
if (itblCustomerBrowser.getRowCount() > 0) {
iCustomerNo = itblCustomerBrowser.getValueAt(
itblCustomerBrowser.getSelectedRow(), 3).toString();
} else {
iCustomerNo = "";
}
((CustomerBrowserInf) getFrameOwner()).setCustomer(iCustomerNo);
dispose();
}

public void setFrameOwner(UIDialog pFrame) {
iFrame = pFrame;
}

//this method retrieves data from database as a vector and set it in this dialogs jtable
public void getBrowserRecords() throws PSFException, SQLException {
int cono = Integer.parseInt(Configuration.getParameter(ConfigSetting.COMPANY_NO));
Vector prevData = null;
TableColumnModel tbcCustModel = null;
TableColumn tbcCust = null;
// iFlag = 1;
if (iCustomerQtbl == null) {
iCustomerQtbl = new CustomerBrowserTableModel();
iCustomerQtbl.setTotalRows(new Vector(5));
}
OprOrders iOprDelMethod = new OprOrders(cono, "", "", 0);
prevData = iOprDelMethod.getCustomerBrowsRecord(gettxtCustomerKey().getText().trim(), gettxtCustomerName().getText().trim(),gettxtTelephone().getText().trim(), gettxtCustomer().getText().trim(), getCustOrdType1(),getCustOrdType2(),cono,iPageNumber,iRecordsPerPage,iFlag);
iRecordsOnPage = iOprDelMethod.getRecordsOnPage();
iCustomerQtbl.setTotalRows(prevData);
gettblCustomer().setModel(iCustomerQtbl);
gettblCustomer().tableChanged(new TableModelEvent(iCustomerQtbl, 1, 1, -1, 0));
gettblCustomer().repaint();
tbcCustModel = gettblCustomer().getColumnModel();
tbcCust = tbcCustModel.getColumn(0);
tbcCust.setMinWidth(85);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(1);
tbcCust.setMinWidth(200);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(2);
tbcCust.setMinWidth(90);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(3);
tbcCust.setMinWidth(120);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(4);
tbcCust.setMinWidth(70);
//tbcCust.setPreferredWidth(160);
itblCustomerBrowser.setAutoResizeMode(0);
gettblCustomer().tableChanged(new TableModelEvent(iCustomerQtbl, 1, 1, -1, 0));
gettblCustomer().repaint();
if (prevData.size() > 0)
gettblCustomer().setRowSelectionInterval(0, 0);
gettxtCustomer().requestFocusInWindow();
}

public void doEvents(KeyEvent pKeyEvent) {
if (pKeyEvent.getKeyCode() == 33) {
if (iPageNumber > 0) {
iPageNumber--;
onNext();
}
}
if (pKeyEvent.getKeyCode() == 34) {
if (iRecordsOnPage >= iRecordsPerPage)
iPageNumber++;
onNext();
}
if (pKeyEvent.getKeyCode() == 27 || pKeyEvent.getKeyCode() == 123) {
onCancel();
}
}

//to show the dialog
public boolean initialize(String search) {
boolean retVal = true;
iRecordsPerPage = 10;
setName("dlgCustomerBrowser");
setDefaultCloseOperation(2);
setBounds(129, 70, 665, 340);
setTitle("Customer Browser");
gettxtCustomer().setText(search);
String imageName = null;
imageName = ConfigSetting.IMAGES_PATH;
imageName = imageName + "PSFIcon.gif";
ImageIcon icon = new ImageIcon(imageName);
try {
//populates data in to the table of this dialog
getBrowserRecords();
doCenter(getFrameOwner());
setContentPane(getpnlCustomerBrowser());
gettxtCustomer().requestFocusInWindow();
} catch (PSFException re) {
re.displayMessage("CustomerBrowser", "initialize");
return false;
} catch (SQLException se) {
(new PSFException(se.getErrorCode(), se.toString()))
.displayMessage("CustomerBrowser", "initialize");
return false;
} catch (NullPointerException ne) {
new PSFException(1, ne.toString())).displayMessage("CustomerBrowser", "initialize");
return false;
} finally {
try {
UserSetting.dataStore.closeQueryStatement();
} catch (PSFException re) {
(new PSFException(3, re.toString())).displayMessage(
"CustomerBrowser", "initialize");
return false;
}
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}});
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0, false);
Action escapeAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);
setVisible(true);
return retVal;
}//end of initialize

//returns the panel of this dialog
public UIPanel getpnlCustomerBrowser() {
if (ipnlCustomerBrowser == null) {
ipnlCustomerBrowser = new UIPanel();
ipnlCustomerBrowser.setName("pnlCustomerBrowser");
ipnlCustomerBrowser.setLayout(null);
ipnlCustomerBrowser.setVisible(true);
getpnlCustomerBrowser().add(getlblCustomer(),getlblCustomer().getName());
getpnlCustomerBrowser().add(gettxtCustomer(),gettxtCustomer().getName());
}
return ipnlCustomerBrowser;
}//end of getpnlCustomerBrowser
}//end of class


Thank you
Vijay






The following is the Parent dialog (Cash Order screen)code which will open the child dialog (Customer search browser screen) on f4 key press


public class CashOrder extends UIDialog {

//instance variable declarations for dialog components
private UITextField itxtCustomer;

// Constructor which sets the parent frame
public CashOrder(UIFrame pParentFrame) {

//calling super class constructor passing the instance of parent frame
super(pParentFrame);

//initializing the instance variables
itxtCustomer = null;

}//end construtor

//getter method which returns the instance of textfield
public UITextField gettxtCustomer() {
if (itxtCustomer == null) {
//Setting the upper case document
UpperCase uppercase = new UpperCase();
uppercase.setSize(10);
itxtCustomer = new UITextField(uppercase, null, 0);
itxtCustomer.setName("txtCustomer");
itxtCustomer.setBounds(90, 59, 100, 20);

//adding key listner
itxtCustomer.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent pKeyEvent) {
int keyCode = pKeyEvent.getKeyCode();
int modifiers = pKeyEvent.getModifiers();
focus = true;

//on f4 key
if((modifiers!=1 || keyCode!=115)&& pKeyEvent.getKeyCode()==115 && pKeyEvent.getSource() == itxtCustomer) {
focus = false;
//this method opens the child dialog
callCustomerBrowser();
if(Common.isBlank(gettxtCustomer().getText())){
gettxtCustomer().grabFocus();
return;
}//end if
setHeaderData();
focus = true;
gettxtAddressNumber().requestFocusInWindow();
}//end if
//on enter
if (pKeyEvent.getKeyCode() == 10)
if (checkCustomer()) {
gettxtAddressNumber().grabFocus();
setHeaderData();
}//end if
}//end of keyPressed
});//end of addKeyListener

//adding focus listner
itxtCustomer.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {
if(gettxtCustomer().isEditable())
{
if(focus)
{
if (checkCustomer()) {
//gettxtAddressNumber().grabFocus();
setHeaderData();
}else{
focus = false;
}
}
}
}
});
}
return itxtCustomer;
}//end of gettxtCustomer

/*** This method opens the customer search browser upon pressing F4 in the Cash Order Screen on the Customer Number Field.
public void callCustomerBrowser() {
//refer below CustomerBrowser class
CustomerBrowser custBrowser = new CustomerBrowser(this);
custBrowser.setFrameOwner(this);
custBrowser.setSearchValue(gettxtCustomer().getText());
custBrowser.setIFlag(iFlag);
custBrowser.setCustOrdType1(getCustOrderType1());
custBrowser.setCustOrdType2(getCustOrderType2());
custBrowser.initialize(itxtCustomer.getText().trim());
}//end of callCustomerBrowser
}//end of class




The following is the child dialog (Customer search browser screen)code which is opened from Parent dialog (Cash Order screen)on f4 key press

public class CustomerBrowser extends UIDialog {


public CustomerBrowser(UIDialog pDialog) {
//pDialog is CashOrder instance
super(pDialog, true);
}

//This method retuns the instance of select button
public UIButton getbtnOK() {
if (ibtnOK == null) {
ibtnOK = new UIButton();
ibtnOK.setName("btnOK");
ibtnOK.setText("Select");
ibtnOK.setBounds(570, 200, 80, 25);
ibtnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onOK();
}
});
ibtnOK.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent pKeyEvent) {
doEvents(pKeyEvent);
}
});
}
return ibtnOK;
}


public UIDialog getFrameOwner() {
return iFrame;
}


//This method disposes the dialog when cancel button is clicked
public void onCancel() {
dispose();
}

//this method is called when select button is pressed
//this is where this screen merges in to the parent screen (CashOrder screen)
public void onOK() {
if (itblCustomerBrowser.getRowCount() > 0) {
iCustomerNo = itblCustomerBrowser.getValueAt(
itblCustomerBrowser.getSelectedRow(), 3).toString();
} else {
iCustomerNo = "";
}
((CustomerBrowserInf) getFrameOwner()).setCustomer(iCustomerNo);
dispose();
}

public void setFrameOwner(UIDialog pFrame) {
iFrame = pFrame;
}

//this method retrieves data from database as a vector and set it in this dialogs jtable
public void getBrowserRecords() throws PSFException, SQLException {
int cono = Integer.parseInt(Configuration.getParameter(ConfigSetting.COMPANY_NO));
Vector prevData = null;
TableColumnModel tbcCustModel = null;
TableColumn tbcCust = null;
// iFlag = 1;
if (iCustomerQtbl == null) {
iCustomerQtbl = new CustomerBrowserTableModel();
iCustomerQtbl.setTotalRows(new Vector(5));
}
OprOrders iOprDelMethod = new OprOrders(cono, "", "", 0);
prevData = iOprDelMethod.getCustomerBrowsRecord(gettxtCustomerKey().getText().trim(), gettxtCustomerName().getText().trim(),gettxtTelephone().getText().trim(), gettxtCustomer().getText().trim(), getCustOrdType1(),getCustOrdType2(),cono,iPageNumber,iRecordsPerPage,iFlag);
iRecordsOnPage = iOprDelMethod.getRecordsOnPage();
iCustomerQtbl.setTotalRows(prevData);
gettblCustomer().setModel(iCustomerQtbl);
gettblCustomer().tableChanged(new TableModelEvent(iCustomerQtbl, 1, 1, -1, 0));
gettblCustomer().repaint();
tbcCustModel = gettblCustomer().getColumnModel();
tbcCust = tbcCustModel.getColumn(0);
tbcCust.setMinWidth(85);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(1);
tbcCust.setMinWidth(200);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(2);
tbcCust.setMinWidth(90);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(3);
tbcCust.setMinWidth(120);
//tbcCust.setPreferredWidth(160);
tbcCust = tbcCustModel.getColumn(4);
tbcCust.setMinWidth(70);
//tbcCust.setPreferredWidth(160);
itblCustomerBrowser.setAutoResizeMode(0);
gettblCustomer().tableChanged(new TableModelEvent(iCustomerQtbl, 1, 1, -1, 0));
gettblCustomer().repaint();
if (prevData.size() > 0)
gettblCustomer().setRowSelectionInterval(0, 0);
gettxtCustomer().requestFocusInWindow();
}

public void doEvents(KeyEvent pKeyEvent) {
if (pKeyEvent.getKeyCode() == 33) {
if (iPageNumber > 0) {
iPageNumber--;
onNext();
}
}
if (pKeyEvent.getKeyCode() == 34) {
if (iRecordsOnPage >= iRecordsPerPage)
iPageNumber++;
onNext();
}
if (pKeyEvent.getKeyCode() == 27 || pKeyEvent.getKeyCode() == 123) {
onCancel();
}
}

//to show the dialog
public boolean initialize(String search) {
boolean retVal = true;
iRecordsPerPage = 10;
setName("dlgCustomerBrowser");
setDefaultCloseOperation(2);
setBounds(129, 70, 665, 340);
setTitle("Customer Browser");
gettxtCustomer().setText(search);
String imageName = null;
imageName = ConfigSetting.IMAGES_PATH;
imageName = imageName + "PSFIcon.gif";
ImageIcon icon = new ImageIcon(imageName);
try {
//populates data in to the table of this dialog
getBrowserRecords();
doCenter(getFrameOwner());
setContentPane(getpnlCustomerBrowser());
gettxtCustomer().requestFocusInWindow();
} catch (PSFException re) {
re.displayMessage("CustomerBrowser", "initialize");
return false;
} catch (SQLException se) {
(new PSFException(se.getErrorCode(), se.toString()))
.displayMessage("CustomerBrowser", "initialize");
return false;
} catch (NullPointerException ne) {
new PSFException(1, ne.toString())).displayMessage("CustomerBrowser", "initialize");
return false;
} finally {
try {
UserSetting.dataStore.closeQueryStatement();
} catch (PSFException re) {
(new PSFException(3, re.toString())).displayMessage(
"CustomerBrowser", "initialize");
return false;
}
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}});
KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0, false);
Action escapeAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
};
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
getRootPane().getActionMap().put("ESCAPE", escapeAction);
setVisible(true);
return retVal;
}//end of initialize

//returns the panel of this dialog
public UIPanel getpnlCustomerBrowser() {
if (ipnlCustomerBrowser == null) {
ipnlCustomerBrowser = new UIPanel();
ipnlCustomerBrowser.setName("pnlCustomerBrowser");
ipnlCustomerBrowser.setLayout(null);
ipnlCustomerBrowser.setVisible(true);
getpnlCustomerBrowser().add(getlblCustomer(),getlblCustomer().getName());
getpnlCustomerBrowser().add(gettxtCustomer(),gettxtCustomer().getName());
}
return ipnlCustomerBrowser;
}//end of getpnlCustomerBrowser
}//end of class
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijaya, the code tags should go around the code, not be placed in the middle.

There are two ways of adding code tags:
1) Just click on the Code button, then fill in the code between the [code] and [/code]
2) Select your code and then press the Code button.
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
brilliant
 
vijaya raghva naidu rambha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is ther any one can help online .
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Also, it's time you create an SSCCE click on the acronym from this code, as it's really hard to see the problem in 800+ lines.

why haven't you created a SSCCE yet? its of no use to repeatedly post 800+ lines of code as has already been pointed out...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> is ther any one can help online .

this is the way it works:

you want 'free' help, so you have to simplify the problem as much as possible for the 'free' helpers.

posting your code in long-winded or no-code-tag format will just get your post by-passed (by most of those who may have the solution),
simply because it's too difficult to read.

have another go, reducing the specific problem to it's basic element, then posting that code (inside code tags).

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic