John Palmieri

Greenhorn
+ Follow
since Jul 05, 2001
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 John Palmieri

Hi Jennifer,
Try this
String chgDesc;
String inputValue;
for ( ; ; )
{
inputValue = JOptionPane.showInputDialog(null,"Key a description of the change.","Change Order",JOptionPane.INFORMATION_MESSAGE);
if (inputValue == null)
{
return;
}
else
{
if(inputValue.trim().length() != 0)
{
chgDesc = inputValue;
break;
}
}
} // for ( ; ; )
System.out.println("You typed: " + inputValue);
[ October 23, 2002: Message edited by: John Palmieri ]
[ October 23, 2002: Message edited by: John Palmieri ]
17 years ago
Hello All,
I would like to know if anyone has any full working examples of sorting a jtable on multiple columns. I have the following data items in a table.
When the user clicks on the market column,
the results should be sorted by market, code,sequence like..
market media code sequence
BF TV 7 1
CA LM 2 1
CA LM 5 1
CA LM 5 2
HT TV 1 1
HT TV 1 2
HT TV 1 3
NY OD 3 1
if the user sorts on media, the code should be ordered by media, code, sequence..
market media code sequence
CA LM 2 1
CA LM 5 1
CA LM 5 2
NY OD 3 1
BF TV 7 1
HT TV 1 1
HT TV 1 2
HT TV 1 3
The problem is that I have multiple rows in the table that relate to each other and therfore need to keep them together on any sort that is done.
The rows need to be always sorted first by clicked column and then by code and sequence.
I am using the sort logic from this site as a starter..
http://www2.gol.com/users/tame/swing/examples/JTableExamples5.html
It only allows sorting on one column.

Any help would be appreciated
John.
17 years ago
Hello,
Can any one tell me why the below code does not print the title bar and surronding window border.
I took this code straight from a sun tutorial.
Does anyone know how to get these parts of the application to print ?
Thanks,
John.
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
public class ComponentPrinterFrame
extends JFrame
implements Printable {
public static void main(String[] args) {
ComponentPrinterFrame cpf = new ComponentPrinterFrame();
cpf.setVisible(true);
}
public ComponentPrinterFrame() {
super("ComponentPrinterFrame v1.0");
createUI();
}
protected void createUI() {
JPanel panel = new JPanel();
JButton printButton = new JButton("Print");
panel.add(printButton);
panel.add(new JList(new Object[] { "One", "Two", "Three" }));
panel.add(new JButton("Push me"));
panel.add(new JCheckBox("Chess", true));
panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
printButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(ComponentPrinterFrame.this);
if (pj.printDialog()) {
try { pj.print(); }
catch (PrinterException pe) {
System.out.println(pe);
}
}
}
});
setContentPane(panel);
setSize(400, 400);
// Center.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
int x = (screenSize.width - frameSize.width) / 2;
int y = (screenSize.height - frameSize.height) / 2;
setLocation(x, y);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public int print(Graphics g, PageFormat pf, int pageIndex) {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)g;
g2.translate(pf.getImageableX(), pf.getImageableY());
getContentPane().paint(g2);
return PAGE_EXISTS;
}
}
18 years ago
No, the Key listeners are different. I set one up for the JButton and one for the JList.
18 years ago
Hello,
I am having a problem with Key Listeners. I have an application that has a JTabbedPane. On 1 page I have several JButtons with Key Listeners attached to them. I detect if the enter key has been struck, If so I execute some code. On the second page I have a JList with a Key Listener attached, If a user hilights a selection and presses enter, some code gets executed.
Here is the problem. I am tabbing throught the app with the tab key. When I get to the list and the list has focus and is hi-lighted, So does a JButton on the first page, when I hit the enter key on the list, the proper code gets executed, but then somehow the Key Listener for the Jbutton on the first page get fired and that code executes. I am not even on that page. Why does the code get executed ! I can put a ugly work around and check to make sure the user is on the page and only execute the code if the page is selected, but I would like a more elegant solution.
Any thoughts would be much appreciated.
Thanks,
John Palmieri
18 years ago
When you marshal data you need to make sure that the objects that you are dealing with implement the serializable interface. I don't think the image class implements this interface.
Good Luck.
John Palmieri
18 years ago
Hello,
I am having a problem with the look and feel methods. I have a applet that can run either as an applet or an application. If it is run as a application, The code puts the applet into a JFrame.
This works, but the look and feel always seems to be metal. I want the look and feel to be windows. How can I accomplish this ?
This is code that was built with Jbuilder 5 with some additions
from me trying to accomplish what I want. when I switch to Jbuilders UI designer the screen pick up the windows look and feel.
I am using JDK 1.3.
Here is the code...
package untitled29;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class Applet2 extends JApplet {
boolean isStandalone = false;
JButton jButton1 = new JButton();
JComboBox jComboBox1 = new JComboBox();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public Applet2() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(110, 39, 103, 27));
this.getContentPane().setLayout(null);
jComboBox1.setBounds(new Rectangle(87, 103, 156, 21));
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jComboBox1, null);
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
/**Main method*/
public static void main(String[] args) {
Applet2 applet = new Applet2();
applet.isStandalone = true;
JFrame frame;
frame = new JFrame() {
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public synchronized void setTitle(String title) {
super.setTitle(title);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
}
};
String laf = UIManager.getSystemLookAndFeelClassName();
try
{
UIManager.setLookAndFeel(laf);
SwingUtilities.updateComponentTreeUI(frame);
} catch (UnsupportedLookAndFeelException exc) {
System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
} catch (Exception exc) {
System.err.println("Error loading " + laf + ": " + exc);
}
Frame[] frames = frame.getFrames();
for(int f = 0; f < frames.length; f++) {
SwingUtilities.updateComponentTreeUI(frames[f]);
frames[f].validate();
Window[] windows = frames[f].getOwnedWindows();
for(int w = 0; w < windows.length; w++) {
SwingUtilities.updateComponentTreeUI(windows[w]);
windows[w].validate();
}
}

frame.setTitle("Applet Frame");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
}
18 years ago
Hello,
I am trying to write a KeyListener that can detect when the tab key is pressed within a JTextField. The Listener detects all keys accept the tab key. It seems that some lower level method is consuming the key before it get to my listener.
My application needs to put up a dialog if the tabs out of the text field.
Any help would be appreciated.
John Palmieri
19 years ago