Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Mariusz Malinowski

Greenhorn
+ Follow
since Dec 15, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mariusz Malinowski

Ok, this problem is related with jsf page life cycle:

http://forums.sun.com/thread.jspa?threadID=736104

So whenever you try to get value for the first time you will get null. Second attempt will give you expected value.
14 years ago
JSF
I have similar problem. I try to get value from ice:inputTextarea and I get null. Did you find solution?
14 years ago
JSF

Is it the console into which you type "appclient -client TheNameOfTheAppClient.jar" to start the app, or is it the one that gets started when you double-click a jar file, or something else entirely?



Actually, I've created run.but file which contains:
appclient -client TheNameOfTheAppClient.jar

and I execute it via WindowsCommander 5.0

Regards,

Mariusz

Now in the bat file that starts the app server, reference this new copy of cmd.exe instead of the original one.[/QB]



Hi,

Thanks for your response but I think we are talking about two different things...
Your description refers to the server console. The problem I presented is how to turn off client console when I load my client's swing application:

appclient -client TheNameOfTheAppClient.jar

If you have any idea I would be grateful.

Regards,

Mariusz
As far as I know this is possible in J2SE using javaw.exe instead of java.exe but how can I do it in J2EE ? I load my app with appclient.bat.

Regards,

Mariusz
Hi,

I wrote j2EE client app in swing and I am using SJSAS PE 8.

The question is: "How to turn off client console (cmd.exe)".

Thank you in advance.

Regards

Mariusz
Hi!

Probably BeanShell would be a good solution.

http://www.beanshell.org

Regards

Mariusz
18 years ago
First of all thank you for your answer.

I checked what it would be if I change initial number of displayed labels:

c.add(new JScrollPane(labelPanel(140)), "Center");

In the result it turned out that panel with 150 labels (initial value 140) appears faster than panel with 90 labels (initial value 40).

That's the thing which makes me wonder.

Regards

Mariusz
18 years ago
Hi!

Once again I post the topic. This time with shortened code.

Whenever I press a button (see my code below) the execution time of my app increases (if run my app, please press the button at least 5 times). Has anyone encountered such a problem when using SpringLayout?

If I change layout the app works fine.
I would grateful for any suggestions.

Mariusz

package problem;
import java.awt.Container;
import java.awt.event.*;
import javax.swing.*;

public class SpringProblem implements ActionListener {

JButton button;
JPanel panel;
int rows;

private SpringProblem(){
JFrame frame = new JFrame();
Container c = frame.getContentPane();
c.add(new JScrollPane(labelPanel(40)), "Center");
c.add(button = new JButton("Add"), "South");
button.addActionListener(this);
frame.pack();
frame.setVisible(true);
}

private JPanel labelPanel(int labelCounter){
panel = new JPanel(new SpringLayout());
for (int i = 0; i < labelCounter; i++) panel.add(new JLabel("OLD"));
// 10 refers to the number of columns
rows = labelCounter/10;
//http://java.sun.com/docs/books/tutorial/uiswing/layout/example1dot4/SpringUtilities.java
SpringUtilities.makeCompactGrid(panel, rows, 10, 10, 10, 5, 5);
return panel;
}

public void actionPerformed(ActionEvent arg0) {
rows++;
SwingUtilities.invokeLater(new Runnable(){
public void run() {
for (int i = 0; i < 10; i++) panel.add(new JLabel("NEW"));
SpringUtilities.makeCompactGrid(panel, rows, 10, 10, 10, 5, 5);
panel.revalidate();
}});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
new SpringProblem();
}});
}
}
18 years ago
Hi!

Finally I have found it. I have done "thread dump" and I realized that SpringLayout (or SpringUtilities.class) makes my app slower. Thus I have chosen GridLayout instead of SpringLayout and it works fine.

But for your help Eddie, I wouldn't have found the solution so quickly.
Once again thank you.

Best regards,

Mariusz
////////////////////

package frames;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;

/**
* A frame which contains JLabel components.
*/
public class FrameOne implements ActionListener {

JPanel componentPanel;

public FrameOne() {

JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

// one can change the value of the argument
panel.add(new JScrollPane(componentPanel(40)));

JButton button = new JButton("Add row of components");
button.addActionListener(this);
panel.add(button);

Container c = frame.getContentPane();
c.add(panel);
frame.pack();
frame.setVisible(true);
}

/**
* JPanel with JLabel componets
*
* @param x
* number of JLabel componets
* @return
*/
private JPanel componentPanel(int x) {
componentPanel = new JPanel();
//!!!
componentPanel.setLayout(new GridLayout(0, 10));

for (int i = 0; i < x; i++) {
JLabel label = new JLabel("old");
componentPanel.add(label);
}
/*
//10 refers to the componentPanel columns number
int rowsCount = componentPanel.getComponentCount() / 10;
*/
return componentPanel;
}

public void actionPerformed(ActionEvent arg0) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FameTwo();
}
});
}

/**
* Adds a row of componets to the first frame.
*/
private class FameTwo implements ActionListener {

JComboBox combo;

JFrame frameTwo;

FameTwo() {
frameTwo = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(innerPanel());

JButton button = new JButton("Add");
button.addActionListener(this);
panel.add(button);

Container c = frameTwo.getContentPane();
c.add(panel);
frameTwo.pack();
frameTwo.setVisible(true);

}

private JPanel innerPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));

JLabel label = new JLabel("Select a row number.");
panel.add(label);

// 10 refers to the componentPanel columns number
int rowsCount = componentPanel.getComponentCount() / 10;

// stores row indexes for JComboBox
Vector vector = new Vector();

for (int i = 1; i <= rowsCount + 1; i++)
vector.addElement(Integer.toString(i));

// contains indexes which point out in which row the new components
// should be added
combo = new JComboBox(vector);
panel.add(combo);

return panel;

}

public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
int rowIndex = Integer.parseInt((String) combo.getSelectedItem()) - 1;
frameTwo.dispose();
for (int i = 0; i < 10; i++) {
JLabel label = new JLabel("new");
componentPanel.add(label, rowIndex * 10 + i);
}

}
});
componentPanel.revalidate();
}
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FrameOne();
}
});
}
}
18 years ago
Hi Eddie!

Thank you Eddie for your reply. I will take your hint into consideration.

Regards,

Mariusz
18 years ago
Hi!

I have got problem with deadlocks. In my application I want to change the contents of JPanel in dynamic way.

The application consists of two JFrames. The first frame contains JPanel with 40 JLabel components. After pressing a button attached to the first frame, the second JFrame appears. The second frame allows to add another 10 JLabel components to the first frame. After performing the 5th attempt of adding another 10 JLabel components there are big deadlocks.

Does any one knows how to avoid it?

I would be grateful for any suggestions.

Mariusz
///////////////////////////////////////////////////////
package frames;

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;

import javax.swing.*;

/**
* A frame which contains JLabel components.
*/
public class FrameOne implements ActionListener {

JPanel componentPanel;

public FrameOne() {

JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

// one can change the value of the argument
panel.add(new JScrollPane(componentPanel(40)));

JButton button = new JButton("Add row of components");
button.addActionListener(this);
panel.add(button);

Container c = frame.getContentPane();
c.add(panel);
frame.pack();
frame.setVisible(true);
}

/**
* JPanel with JLabel componets
*
* @param x number of JLabel componets
* @return
*/
private JPanel componentPanel(int x) {
componentPanel = new JPanel();
componentPanel.setLayout(new SpringLayout());

for (int i = 0; i < x; i++) {
JLabel label = new JLabel("old");
componentPanel.add(label);
}

// 10 refers to the componentPanel columns number
int rowsCount = componentPanel.getComponentCount() / 10;

/**
* A 1.4 file that provides utility methods for creating form- or
* grid-style layouts with SpringLayout. These utilities are used by
* several programs, such as SpringBox and SpringCompactGrid.
*http://java.sun.com/docs/books/tutorial/uiswing/layout/example1dot4/SpringUtilities.java
*/

SpringUtilities.makeCompactGrid(componentPanel, rowsCount, 10, 10, 10,5, 5);
return componentPanel;
}

public void actionPerformed(ActionEvent arg0) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FameTwo();
}
});
}

/**
* Adds a row of componets to the first frame.
*/
private class FameTwo implements ActionListener {

JComboBox combo;

JFrame frameTwo;

FameTwo() {
frameTwo = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(innerPanel());

JButton button = new JButton("Add");
button.addActionListener(this);
panel.add(button);

Container c = frameTwo.getContentPane();
c.add(panel);
frameTwo.pack();
frameTwo.setVisible(true);

}

// Inner panel of the second JFrame
private JPanel innerPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));

JLabel label = new JLabel("Select a row number.");
panel.add(label);

// 10 refers to the componentPanel columns number
int rowsCount = componentPanel.getComponentCount() / 10;

// stores row indexes for JComboBox
Vector vector = new Vector();

for (int i = 1; i <= rowsCount + 1; i++)
vector.addElement(Integer.toString(i));

// contains indexes which point out in which row the new JLabel components
// should be added
combo = new JComboBox(vector);
panel.add(combo);

return panel;

}

public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
int rowIndex = Integer.parseInt((String) combo.getSelectedItem()) - 1;
frameTwo.dispose();

for (int i = 0; i < 10; i++) {
JLabel label = new JLabel("new");
componentPanel.add(label, rowIndex * 10 + i);
}
int rowsCount = componentPanel.getComponentCount() / 10;
SpringUtilities.makeCompactGrid(componentPanel, rowsCount,10, 10,10, 5, 5);
}
});
componentPanel.revalidate();
}
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FrameOne();
}
});
}
}

[ April 09, 2005: Message edited by: Mariusz Malinowski ]
[ April 09, 2005: Message edited by: Mariusz Malinowski ]
18 years ago
Hi!

Using ejbPostCreate (when you develop EJB CMP) you can set CMR fields. Wchich is as far as I know impossible when you use ejbCreate method.
The ejbPostCreate is invoked after ejbCreate method.

Regards,

Mariusz
Hi!

I write J2EE application which contains several EJB CMP and one session stateful bean (the client's application uses Swing based GUI). Because each redeployment takes a lot of time (in particular on my "fast" Pentium II, 192MB RAM) thus I have decided to use MockEJB framework during the process of developing.
I adopted my application to MockEJB (using Aspects/Interceptors for: ejbSelectAll, ejbCreate and so on) but it seems to be impossible to run any swing application with MockEJB and JUnit. The question is: if anyone knows how to avoid this problem. I do not want to make any tests. I just want to run my client's application without any J2EE server.

Maybe I want too much?

Thank you in advance!

Mariusz

[ December 15, 2004: Message edited by: Mariusz Malinowski ]

[ December 15, 2004: Message edited by: Mariusz Malinowski ]
[ December 16, 2004: Message edited by: Mariusz Malinowski ]