Swing/AWT/SWT :: Search For A Key In Properties File - Jbutton Won't Work
Aug 26, 2014
I have a properties file with key values in it, now when I use my search box to search for a key in the properties file to check whether or not it is there - I can't get it to check and return the key value if it is theere. I've tried a few methods but keep getting a null pointer exception when it hits line 15 in the code all the time so I'm stumped at the minute.
My text field is called textFieldSearch
This is my button code
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//search button
//find selected comman
String key_name = textFieldSearch.getText();
[Code] ....
This is my method code
public void FindSelectedKey()
{
if(textFieldSearch != null)
{
properties.getProperty(key_name == textFieldSearch)
}
}
View Replies
ADVERTISEMENT
Feb 18, 2014
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class frmSearch extends JDialog
{
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
JPanel jpnlMain = new JPanel();
[Code] ....
View Replies
View Related
Jan 29, 2014
I have been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
View Replies
View Related
Dec 4, 2014
I'm not too familiar with serialization.It actually I found at this site (Java - Serialization) says that it will write and read properties of an object. I'm not quite sure how this would work as I would have thought that writing it to a text file would just do a toString() when you wrote it, but the page seems to think otherwise, and also names it .ser or something instead of .txt.
I thought, maybe this would work with my idea for a notepad that could store a Font, font color, and other settings, for the file. It would be beyond normal notepads. However, could you do this for a file as it would store text plus other things.
The upshot of this is that the same file, I was hoping to be able to be read by regular text programs like Notepad. However, could Notepad read such a modified file? Also, if notepad wrote to it, would it destroy my font properties and stuff that I'd add to it?
Also, what does this mean:
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
Originally, I was going to use FileAttribute or something like that but it looked hard to do and likely not what I wanted. However, this looks more like what I want, but I'd like to know. This could be a huge breakthrough for a lot of things I was hoping to do but never could think of an efficient way to do.
Update:This serializable thing works great for my text editor but it won't work too hot if another program like Notepad reads it as it will appear like gibberish, including the text.
I had thought of having it make two files, one regular, and one that was serialized, to deal with this, but this doesn't work if I try opening a file that another text editor created that might not have this other serialized version of the file.
Also, I haven't yet tried extending File itself yet. However, I still don't see how it would work the way I'd hoped.
In a way, I want it to be like a RTF with some things used to set te font of the text area when loaded but be able to deal with opening a file made by another text editor and also have another text editor be able to read it even if my text editor created it.
View Replies
View Related
May 25, 2015
Need to know how i can store a value in File which is in Properties?
Here I am placing my Properties code :
ReportHTML C:/bea/user_projects/domains/OICDomain/applications/IIMS/IIMS/target/source/REPORT_HTML_DUMP/
ReportEXCEL C:/bea/user_projects/domains/OICDomain/applications/IIMS/IIMS/target/source/REPORT_EXCEL_DUMP/
My Java File :
File destHtmlFolder = new File("C:/bea/user_projects/domains/OICDomain/DOC_SERVER/REPORT_HTML_DUMP");
File srcExcelFolder = new File("C:/bea/user_projects/domains/OICDomain/applications/IIMS/IIMS/target/source/REPORT_EXCEL_DUMP");
View Replies
View Related
Jul 21, 2014
I am using JPF controllers. Already, i am loading a properties file in the controller
(using annotations @Jpf.Controller(messageBundles = { @Jpf.Message Bundle(bundlePath = "validation.validator.Messages") },).
I have a problem. Depending on one of the request variables, i need to load different properties files. All these property files have same keys, but with different messages. I need to take the user to different sites(though internally, the backend logic remains same...Look and feel of the front end along with messages to be shown change to make the users feel they are being directed to a different site).
I am thinking of loading the properties file from the JSP when the user logs in first time from login page so that these properties are available until the session expires & not read the properties file in Controller.
View Replies
View Related
Jan 31, 2011
In my java app there is a code which reads the properties file from src/main/resources folder.
Java Code:
@Component("mailerProperties")
public class MailerProperties {
private static Properties properties;
public MailerProperties() {
properties = new Properties();
[Code] ....
Now I need to create a jar file and also remove the properties file from src/main/resources folder and place it outside the jar file(in the same location as jar file) so that data inside it can be changed easily in future.
Question: Currently it uses ClassPathResource("mailer.properties") to read the prop file. What change I need to make to read it from outside the jar file...
View Replies
View Related
Aug 26, 2014
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//find selected command
String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a properties file and if it exists, pull the key and the value back into a panel
View Replies
View Related
Jan 22, 2014
I have `country.properties` file which have values as follows:
1=USA
91=India
20=Egypt
358=Finland
33=France
679=Fiji
and, have a response class file, which is setting a response from database to display it on `JSP` file. The value that I am getting from database is in the form of `code` or `integer`. I needed to have that value from the database and before setting the response I need to use `getProperty(code)` and save the String representation of that code into a new list and then pass that list to `setResponse`. For e.g: This is the value I am getting from database:
col1 | col2 | col3 |
1 helo done
I needed to show on my JSP page as:
col1 | col2 | col3 |
USA helo done
I was following this tutorial [URL].... but not able to exactly understand how to achieve the same.
This is my `DAOImpl` where I needed to `iterate` and save the `mapped key-value` in a new list and then pass to `JSP` page
public class CountDAOImpl implements IDataDAO {
private Connection conn = null;
private Statement statement = null;
private ResultSet rs = null;
private List<String> country_code = new LinkedList<String>();
[Code] ....
View Replies
View Related
Aug 26, 2014
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//find selected command
String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a proeprties file and if it exists, pull the key and the value back into a panel ....
View Replies
View Related
Feb 4, 2015
I'm currently working on a java project simply to learn java. So far, it creates a window and makes a properties file, or appends data to it if it already exists. The problem is that I'm not quite sure how to check if the file already exists to append data to it. I'm currently using a boolean (configCreated) that appends data when true, and creates a file when false. The problem is that this boolean is always false since it's at the beginning.
Java Code:
package Setup;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
[code]...
View Replies
View Related
Mar 26, 2014
Whenever I am running applet using appletviewer I am getting the below warning message:
Can't read Appletviewer properties file.
How to correct this?
View Replies
View Related
Dec 19, 2013
When we have a property in the jnlp file that has accented characters (i.e. Mañana), the System.getProperty() call is returning null. This is working fine with Java 7 Update 40, and accented characters in the <information> section of the jnlp file are working fine under Java 7 Update 45, but not in the <resources> section.
Here is an example:
<property name="jnlp.title" value="Mañana"/>
System.getProperty("jnlp.title") returns null
Is there a workaround?
View Replies
View Related
Nov 27, 2014
I need to write the exact directory path like C:LisaestUpdate to a properties file.
I am trying it by
FileInputStream in = new FileInputStream(test.properties);
Properties props = new Properties();
props.load(in);
in.close();
FileOutputStream out = new FileOutputStream(newprop.properties);
props.setProperty("myDirectory","C:Lisa estUpdate" );
props.store(out, null);
out.close();
but the properties file is updated as C:Lisa estUpdate
Extra comes before :.
How can I remove that.
Even I tried it with an command but got same output.
View Replies
View Related
May 25, 2014
I have a Jbutton in my application named as SUBMIT,on clicking SUBMIT the text of jButton changes to ABORT. I wish to apply enter key listener on both the SUBMIT and ABORT button in my applcation, however I am not able to get the text of the button in key listener,so that i can apply my code based on the current text of Button.
View Replies
View Related
Aug 3, 2014
I have a jButton that when the action perform runs it only does part of the tasks some of the code doe not appear to run and i just can not figure out why i have tried wrapping parts of it in an if statement and it still do not run so here is the code behind the button:
in the code the parts that do not run are jTextField10.setText("Working Please Wait"); and jButton15.setVisible(false);
what i am expecting to happen is the text field has the words Working Please Wait placed in it , this does not happen and the button should be hidden to prevent it being clicked a second time again this does not happen
the rest of the code works as expected
InputStream inStream;
OutputStream outStream;
try {
File afile = new File("C://templates//amendments.xls");
File bfile = new File("C://amendments.xls");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
[code]....
View Replies
View Related
Sep 25, 2014
I'm not sure what I'm doing wrong but none of the buttons will show below. I tried using .add with the container name but it kept giving me an error. When I just put add.(); it seems fine but then nothing shows. Is there something I'm missing that's required?
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@SuppressWarnings("serial")
[code]....
View Replies
View Related
Mar 5, 2014
I was suspecting I had a jButton not working, so I added a console print to test. See below. When I click the button, the console doesn't display anything. Am I using the button wrong?
private void jButtonUpdateItemsMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}
I have also tried the following with the same results (or lack of).
private void jButtonUpdateMajorDeckItemsActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}
View Replies
View Related
Feb 23, 2014
Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:
try {
button[i].setIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." + (i+1)))));
}
catch (NullPointerException ex) {
}
Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.
How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.
Here is the whole code...
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.io.File.*;
[Code] ....
View Replies
View Related
Jan 27, 2013
refer to this code~
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;
[Code] ....
View Replies
View Related
Aug 3, 2014
I am relatively new to java. . I cannot...(actually do not know) how to change the actionlistener (actionPerformed) after the second click in an array of JButtons. This is how the program performs right now.
On the 1st click on the grid, the border of the button clicked will change to 'blue' and another button will change its boarder to 'red'. on the next click the same action is performed.
What I need is to change action when the 'red' bordered button is clicked, lets say change the color of the buttons from the 'red' to the 'blue' buttons.(x 3 buttons).
The logic about how to perform the final result I think I can do on my own but my problem is how to change the action when the red bordered button is clicked.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
[Code] .....
View Replies
View Related
Mar 3, 2015
one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.
View Replies
View Related
Jan 30, 2015
what I have already tried:
to set the margin of a button - didn´t work
to set anything like padding - didn´t found something for java
to set an empty border - didn´t work
I don´t know what to try next.
My main problem is to enlarge the clickable area without resizing the buttons image.
View Replies
View Related
Oct 14, 2014
We are creating a quiz as a school program, we are using netbeans and we have a little problem. The problem is that our JButton opens a new JFrame in a new window and we want it to stay in the same window. The code we are using is:
private void PlayButtonActionPerformed(java.awt.event.ActionEve nt evt) {
Question1 s = new Question1 ();
s.setVisible(true);
}
Is it possible to make it stay in the same window?
View Replies
View Related
Mar 10, 2014
how can i execute the main class into a JButton.
Example: Main Class
public class ComparativoV3{
public void loadComparative(String path){
}
public void compareDbs(){
[Code].....
how to set it up the private void CompareActionPerformed(java.awt.event.ActionEvent evt) as the ComparativeV3 main class, not giving it any argument, because the files are load from the arguments section & it reads diferent files with diferent arguments.
View Replies
View Related
Apr 14, 2015
I am trying to plot a graph and graph should display when JButton is clicked. To create data set, I am taking some value through JTextField and then created a chart and plotted it. I've got a problems: the chart doesn't refresh/update when I change the text field value.
public class Test2 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private ChartPanel chartPanel;
private JTextField textField_1;
double a;
[Code] ....
View Replies
View Related