Both of your returns are in conditional statements. The compiler requires a guaranteed return value for all possible conditions.
Add a default return value at the end to cover the case of your other conditions not being satisfied.
Both of your returns are in conditional statements. The compiler requires a guaranteed return value for all possible conditions.
Add a default return value at the end to cover the case of your other conditions not being satisfied.
Yes, you're just putting the text of the selected checkboxes into your array. With a fixed size array though, the filter array will contain nulls in the slots that correspond to the unselected fields.
So if only box "1" and "3" is selected your array will contain ["1",null,"3",null,null...]. That is why I mentioned that you may want to add the fields to another list instead, so you don't have the nulls to mess with.
I can't make more specific suggestions because I don't know how you are actually using that filter against the Excel files.
Basically all you are needing to do is
for(int i=0; i<checkList.size(); i++) {
JCheckBox cb = checkList.get(i);
// if cb.isSelected() add cb.getText() to some list or array
}
I don't think you need to do that in your listener unless you are updating the results immediately as the user checks the boxes. You said your were extracting data from Excel, so I assumed the user made their choices and then hit "Go" or whatever. You can produce the list when they hit "Go".
I would actually recommend adding the field names to another List or Set instead of a fixed size array that will contain some nulls.
Several things here:
String[] filter = null;
You have to actually initialize the array before you can use it,
String[] filter = new String[size]; // proabably same size as number of checkboxes?
Not sure what you are trying to do with this
evt.getActionCommand().equals(checkList)
Comparing a string to an ArrayList?
Also can't figure what Check is here
Check.isSelected()
but you need to get() each checkbox from the checkList in your loop.
You already have a File object from the open dialog, so use file.getPath() instead of file.getName().
Those are the string representations of the components themselves.
You need to use the textfield.getText() or combobox.getSelectedItem() to access the values they contain.
I was doing some reading today as well and saw a reference to another layout GroupLayout?
I would not recommend trying to work with GroupLayout without a GUI designer. It's even more complex than GridBagLayout.
Basically, yes, with some syntax correction. Is your search filter an array or a string that you pass to HSSF?
I'm not following what you mean with arrays and splitting anything. You simply need to supply the full path to the file.
c:/whateverDir/whateverFile.xls
//someNetworkLocation/whateverDir/whateverFile.xls
That's fine. You'll just need to supply the full path to the resource in that case.
Post the exact error message.
Edit: Nevermind. Check your spelling of JCheckBox.
Yeah, that's simply a path error. You'll need to supply a full path to the file unless it's in a sub-directory of your program folder.
Are you using Java 1.5 or later? Did you add List and ArrayList to your imports?
If the path of the filename cannot be found relative to the directory in which the program is executing, you'll need to provide a more complete path to the file. You didn't post the error message, but it sounds like a FileNotFoundException?
GridLayout maintains equally sized grid cells along the horizontal and vertical. If you need to vary the size of the cells, you'll need to subdivide your layout into multiple panels with their own groups of controls or use a GridBagLayout.
GridBagLayout is a lot more flexible, but it's also much more complex and comes with a bit of a learning curve.
The way you create the boxes wouldn't change, you'd just need to create a list in your class to hold them
List<JCheckBox> checkList = new ArrayList<JCheckBox>();
and when you're adding them to the form (before/after, doesn't matter), add them to your list as well
checkList.add(checkBox);
Looks to me like you just want to set the text of your text fields back to zero or empty. You can just call setText(String) on each of them.
The state of the flags can be stored in a Map such as
Map<String, Boolean> filterMap = new HashMap<String, Boolean>();
Your listener just needs to set the value for that filter field option to true or false based on whether the box is checked
public void actionPerformed(ActionEvent e) {
filterMap.put(e.getActionCommand(), ((JCheckBox)e.getSource()).isSelected());
}
The method that actually builds the actual search string for Excel just needs to iterate the map and add the fields that are set to true. The ones that are false or not in the map at all don't matter.
Alternately, you could just add all of the JCheckBox components themselves to a List as you create them and iterate that list to build your filter string based on isSelected().
Regex.
Edit: Sorry, cross-posted. ^^ What he said.
Your listener just needs to call repaint(). That will trigger a call to your paintComponent() method on the event dispatch thread.
You can add a repaint() call right after you update your path.
Ok, that means you haven't put in any code to handle the exceptions from new FileOutputStream
. You need to put a try-catch block around that code.
One option would be to use a single listener for all of the check boxes to toggle values in a HashMap<String,Boolean> when they are checked/unchecked. You can then build your Excel filter criteria from the "true" values in that map.
class FilterCheckAction extends AbstractAction{
public void actionPerformed(ActionEvent e) {
filterMap.put(e.getActionCommand(), ((JCheckBox)e.getSource()).isSelected());
}
}
Please post the entire error. The stack trace is much more useful than "an error".
No. If you're too lazy to Google such a basic concept, why should someone else put forth the time to spoonfeed it to you?
If you have acutal questions, after putting in the slightest effort yourself, post them here with whatever code you have started with.
I already have code of my own to write here at work. Give it a go and if you have more questions post them here with your code.
In your listener, you can get a reference to the clicked object with e.getSource()
, which you can then cast to JCheckBox
. You can toggle your variable values based on JCheckBox.isSelected()
.
Lucky guess I suppose ;)
I guess that would depend on what the error was...
Oh, you got the hard one. The easier one asks what color his brown horse was...
Use an ActionListener instead of ChangeListener for your buttons. You can pass the color you wish to change to as a parameter to your setSampleColor() method. Set the panel background to that color before repaint.
Both download and open just fine for me.
Make sure the name of your file is "NestedNumber.java".
Look through the methods on the Character class as well. You may find something useful.
You don't necessarily need to create a new InputMap, you could use the existing for the component. Either way, you need to map the actions for those events now. That is what the action map is for. So for your "UP" action mapping you would have something like the following
board.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke((KeyEvent.VK_UP), 0, false), "UP");
board.getActionMap().put("UP",
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// Whatever you need to do on UP
System.out.println("UP");
}
});
You didn't provide CollegeMember with a zero-argument constructor, which your Lecturer constructors are trying to call implicitly.
You're trying to access the third element of array[] and it doesn't have that many elements. Don't do that.
i just don't know how to use color constructor
Just remove this line
public void Color(int r,int g,int b);
and this line
c = Color.magenta;
Your initial declaration is just fine.
Just below the text "Has this thread been answered?" there is a link to "Mark this Thread as Solved".
Moving to JavaScript.
This was already answered in the OP's other thread for the same question but he chose to ignore the answers:
http://www.daniweb.com/software-development/java/threads/384210/1654757#post1654757
Actually, on line 93 you are declaring a new variable "stkBean" which immediately goes out of scope in your loop.
StkBean stkBean = new StkBean();
Remove the declaration from that and just assign the new instance to your class-level stkBean reference.
Your current code is still using the single instance of stkBean that you initialized at declaration.
Alternately, you could move line 93 up to the beginning of the loop and do away with the class-level variable altogether. You don't have any use for stkBean other than adding to the arraylist.
while (results.next() )
{
StkBean stkBean = new StkBean();
//myList.add((results.getString(1)).trim() );
stkBean.setStkSymbol(results.getString((1)).trim () );
stkBean.setCompanyName(results.getString((2)).trim() );
stkList.add(stkBean);
}//end do-while
Edit: Also, you may want to either override toString() in your StkBean class or print one of the properties like getCompanyName() in your option list output.
Are you creating a new StkBean each iteration of your loop to add to the array list?
You don't want to create a new Date to compare to "d". You want to use the current instance value.
Yes, you declared the variable on line 27, but you haven't actually initialized it prior to using it. You still have to create an instance of new StkBean()
before you can assign any values to it.
I don't see where you have initialized "stkBean" prior to that line.
I'm not really certain what the question even is. It just sounded vaguely like he was asking for some kind of installer.