Help coderanch get a
new server
by contributing to the fundraiser

Steve Dunn

Greenhorn
+ Follow
since Dec 30, 2003
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 Steve Dunn

I'm new to javascript so please bear with me.

Can I embed either a document object reference or a function within a functions argument list and use the result as an input argument?

example:
"<"a href="#" onKlick="viewimage(document.images.Image.src);" ">" "<"img name="Image" src=" "<"%=imagepath%">"/193x180map/"<"%=ImageName%">""

Also, within a function, can I substitute an argument, input to the function, within a document object?

example: Where the value of 'imageName' is substituted for the image name attribute.
function viewimage (imageName) {
var image = document.images.imageName.value.src.substring(document.images.imageName.value.src.lastIndexOf("/")+1);
}


I appreciate any and all assistance.

[ September 14, 2006: Message edited by: Steve Dunn ]
[ September 14, 2006: Message edited by: Steve Dunn ]
Michael,

Thanks for your assistance, the code you provided worked. However, it would be helpful if you could explain why the GridBag RELATIVE setting for c.gridy &/or c.gridheight did not work. According to "Complete Java 2 Certification" if I'm filling the layout from top-left to bottom-right one row at a time, I should be able to set my Constraints one time using the RELATIVE/REMAINDER values.
17 years ago
Here's the rest of my code, all of the jpanels are render correctly. The only problem is the last panel is not visible when the window is displayed.


import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.util.*;
import javax.swing.JPanel;



public class RequestWindow extends JFrame {

private JPanel jContentPane = null;

/**
* This is the default constructor
*/
public RequestWindow() {
super();
initialize();
}



private JPanel getRequestPanel() {

JPanel requestPanel;
String[] statusValues = {"*ALL","Assigned","Unassigned","Open","Completed","Cancelled"};

JLabel projectLbl = new JLabel("Project");
JLabel applAreaLbl = new JLabel("Application Area");
JLabel statusLbl = new JLabel("Status");
JLabel dteRangeLbl = new JLabel("Date Range");
JLabel dteToLbl= new JLabel("To");

JComboBox project = new JComboBox();
JComboBox applArea = new JComboBox();

JComboBox status = new JComboBox(statusValues);

JTextField dteFrom = new JTextField(10);
JTextField dteTo = new JTextField(10);

requestPanel = new JPanel(new BorderLayout());
requestPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Request Selection"));

JPanel rp_North = new JPanel(new FlowLayout(FlowLayout.CENTER));
rp_North.add(projectLbl);
rp_North.add(project);
rp_North.add(applAreaLbl);
rp_North.add(applArea);
rp_North.add(statusLbl);
rp_North.add(status);

JPanel rp_South = new JPanel(new BorderLayout());
JPanel rp_SouthInner = new JPanel(new FlowLayout(FlowLayout.CENTER));
rp_South.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Date Select"));

rp_SouthInner.add(dteRangeLbl);
rp_SouthInner.add(dteFrom);
rp_SouthInner.add(dteToLbl);
rp_SouthInner.add(dteTo);

rp_South.add(getDateSelectPanel(), BorderLayout.NORTH);
rp_South.add(rp_SouthInner, BorderLayout.SOUTH);

requestPanel.add(rp_North, BorderLayout.NORTH);
requestPanel.add(rp_South, BorderLayout.SOUTH);

return requestPanel;
}

private JPanel getDateSelectPanel() {

JRadioButton none = new JRadioButton("None",true);
JRadioButton entered = new JRadioButton("Entered");
JRadioButton assigned = new JRadioButton("Assigned");
JRadioButton completed = new JRadioButton("Completed");

ButtonGroup bg = new ButtonGroup();
bg.add(none);
bg.add(entered);
bg.add(assigned);
bg.add(completed);

JPanel dateSelectPanel = new JPanel(new GridLayout(1,0));

dateSelectPanel.add(none);
dateSelectPanel.add(entered);
dateSelectPanel.add(assigned);
dateSelectPanel.add(completed);

return dateSelectPanel;
}

private JPanel getFieldSelectPanel() {

JPanel fieldSelectPanel;

JCheckBox reqNbr = new JCheckBox("Request Nbr");
JCheckBox reqType = new JCheckBox("Type");
JCheckBox reqRank = new JCheckBox("Rank");
JCheckBox reqDate = new JCheckBox("Date");
JCheckBox reqDesc = new JCheckBox("Description");
JCheckBox reqNotes = new JCheckBox("Notes");
JCheckBox reqResolution = new JCheckBox("Resolution");
JCheckBox reqAssigned = new JCheckBox("Assigned To");
JCheckBox reqEstHrs = new JCheckBox("Estimate");
JCheckBox reqActHrs = new JCheckBox("Actual");

fieldSelectPanel = new JPanel(new GridLayout(5,2,0,0));
fieldSelectPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Field Selection"));
fieldSelectPanel.add(reqNbr);
fieldSelectPanel.add(reqType);
fieldSelectPanel.add(reqDate);
fieldSelectPanel.add(reqRank);
fieldSelectPanel.add(reqDesc);
fieldSelectPanel.add(reqNotes);
fieldSelectPanel.add(reqResolution);
fieldSelectPanel.add(reqAssigned);
fieldSelectPanel.add(reqEstHrs);
fieldSelectPanel.add(reqActHrs);

return fieldSelectPanel;
}

private JPanel getRequestFilePathPanel() {

JLabel fileLbl = new JLabel("File");
JTextField file = new JTextField(30);
JButton browse = new JButton("Browse");

JPanel requestFilePath = new JPanel(new FlowLayout(FlowLayout.LEFT));
requestFilePath.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Output"));

requestFilePath.add(fileLbl);
requestFilePath.add(file);
requestFilePath.add(browse);

return requestFilePath;
}



/**
* @param args
*/
public static void main(String[] args) {

RequestWindow rw = new RequestWindow();

rw.setTitle("Request Window");

rw.pack();
rw.setVisible(true);

}


private void initialize() {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}

catch(ClassNotFoundException cnfe) {

}
catch (IllegalAccessException ilae) {

}
catch (UnsupportedLookAndFeelException ulfe) {

}
catch (InstantiationException ie) {

}

JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());

}


private JPanel getJContentPane() {
if (jContentPane == null) {

jContentPane = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTH;

JLabel ip = new JLabel(new ImageIcon("c:\\HeaderImage.jpg"));
jContentPane.add(ip,c);

c.gridy = GridBagConstraints.RELATIVE;
c.anchor = GridBagConstraints.CENTER;
c.gridheight = GridBagConstraints.RELATIVE;

jContentPane.add(getRequestPanel(),c);

jContentPane.add(getFieldSelectPanel(),c);

jContentPane.add(getRequestFilePathPanel(),c);

}
return jContentPane;
}


}
17 years ago
The last of the 5 jpanels.
17 years ago
I'm building a gui using a jframe as the base window and adding jpanel's to the frame using a gridbaglayout manager. The gridbaglayout is a single column with 5 rows; a jlabel with image and four jpanel's.The first jpanel is a nested panel with 2 borderlayout panels each with 2 flowlayout panels. My problem is the last panel is not visible when i run the application. If i resize the window the panel is there. I've tried adjusting the jframe height, row & column weights in the gridbagconstraints & removing/repositioning panels. If i remove or reposition the jlabel w/image then only the first two jpanels are visible; the same happens if i remove or reposition any of the other jpanels.

Can someone provide some assistance! Any help would be greatly appreciated. Following is some of my code.

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.util.*;
import javax.swing.JPanel;



public class RequestWindow extends JFrame {

private JPanel jContentPane = null;

/**
* This is the default constructor
*/
public RequestWindow() {
super();
initialize();
}



public static void main(String[] args) {

RequestWindow rw = new RequestWindow();

rw.setTitle("Request Window");

rw.pack();
rw.setVisible(true);

}


private void initialize() {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}

catch(ClassNotFoundException cnfe) {

}
catch (IllegalAccessException ilae) {

}
catch (UnsupportedLookAndFeelException ulfe) {

}
catch (InstantiationException ie) {

}

JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());

}


private JPanel getJContentPane() {
if (jContentPane == null) {

jContentPane = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();

c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTH;

JLabel ip = new JLabel(new ImageIcon("c:\\HeaderImage.jpg"));
jContentPane.add(ip,c);

c.gridy = GridBagConstraints.RELATIVE;
c.anchor = GridBagConstraints.CENTER;
c.gridheight = GridBagConstraints.RELATIVE;

jContentPane.add(getRequestPanel(),c);

jContentPane.add(getFieldSelectPanel(),c);

jContentPane.add(getRequestFilePathPanel(),c);

}
return jContentPane;
}


}
17 years ago
I use the vector as part of the ListSelectionListner to identify the book code for a selected book title in the list, then query the book table for the selected book and load to text fields for update.

JList "titleList" only has the ListSelectionListner added. I have ActionListner on buttons I use to identify when an ADD or DELETE occurs then call method loadScrollPanel.
18 years ago
I'm building a JLIST from a JDBC query and I want to be able to reload the list whenever the Access table I built the list from is is updated (records added or deleted). I'm able to build the initial list just fine using the following method; which I also use to reload the list when and add or delete event occurrs. However, the list doesn't seem to reload. Can someone tell me what I'm doing wrong?

Thanks for your help,


private void loadScrollPanel() {

vBookCodes = new Vector();
titleList.setModel(new DefaultListModel());

DefaultListModel dlm = (DefaultListModel) titleList.getModel();

try{
BookDB.connect();
rsBooks = BookDB.open();

while(rsBooks.next()) {
dlm.addElement(rsBooks.getString("BookTitle"));
vBookCodes.add(rsBooks.getString("BookCode"));
}

BookDB.close();

titleList.setModel(dlm);

titleScroll.setViewportView(titleList);
}

catch (ClassNotFoundException e){
JOptionPane.showMessageDialog(null, "cnf loadScrollPane " + e.getMessage());
System.exit(1);
}

catch (SQLException e){
JOptionPane.showMessageDialog(null, "sql loadScrollPane " + e.getMessage());
}
}
18 years ago