Prompt text for JFormattedTextField is not working - java

I wanted to add a text prompt for my JFormattedTextField and I searched it on google on how I could do this. I got a lot of hits for the following code below but when I put it into my code in eclipse it doesn't recognize any of it. Can someone tell me why?
Here are two possible ways to add a text prompt:
PromptSupport.setPrompt("prompt", textComponent);
TextPrompt p = new TextPrompt("text", textComponent);
I got it from the following link:
How to display a default message in JTextField java

the most probable reasons why eclipse doesn't recognize any of these classes are because they are not a part of the JDK.
PromptSupport is a part of the XSwingX library. If you want to use this library for setting PromptText, you will have to download the jar and add it to the build path of the project.
I am not sure whether TextPrompt is the class XSwingX as well.

Related

IntelliJ Java Configurations

I am new learning Java in IntelliJ and I have a problem edit configurations which I don't know how to run my program HelloWorld. Some pictures are as below:
This is my code.
This is what presents after I click Run
It appears Edit configurations.
And then I don't know what should I do.
I think you have not set an SDK for your project, try adding an SDK, if that doesn't work you have to download and install it first. And next time please add your code as text with the "{ }" tool not as a picture.
And to print something into the console you have to do it like this:
System.out.println("Hello World")
And also if you want to print to the terminal, the right way to do it is...
System.out.println("Text here")
And if you dont want to break the line when writing, you can do this.
System.out.print("Text here")
When using "" inside of an print method, it indicates that you want to print a String.

Can't add CircularSeekBar to my project

Hey,
I've been trying for hours to add this to my project to make a fuel gauge.
I've been doing everything as it is shown in the instructions. But I happen to encounter some problems that I can't resolve.
I've pasted the .java file as instructed evidence but I get 2 problems here. First the "gradle" folder is highlighted in red and the .java file in question has a red J in its icon. I've tried to search how to solve those but nothing works for me.
I don't know if the next problem is because of the previous ones but when I try to add xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"
in the parent view in xml file i get the error to use xmlns:app="http://schemas.android.com/apk/res-auto" to "automatically" search for the custom view but it doesn't work. So I can't import the .java in the activity(its like its not there") and I can't use it in the layout file.
Please help I've tried searching on SO but I could't find anything to work for me.
Beginner android dev here :)
Thanks in advance.
I have tried to use your given customseekbar in a basic hello world app. It works perfectly fine for me.
I see you've put the com/devadvance/circulerseekbar/circularseekbar.java in the src folder instead of main/java. So it should be in src/main/java/com/devadvance/circulerseekbar/circularseekbar.java.
Also I found out that you don't really need to add the namespace xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest instead the default namespace of xmlns:app="http://schemas.android.com/apk/res-auto in the xml file should be fine.
Finally, don't forget to add import com.myapplication.R; in the customseekbar class to use your resource class R in the customseekbar class.
Hope it helps, otherwise let me know!

Matlab doesn't see .jar file

Ok, I'm stumped here. I'm using Matlab version 2013b with a Java RTE of 1.7.0_11 and I'm trying to run a simple piece of code to see if Matlab is able to read the .jar file and nothing seems to be working.
Here is the Java code, which is compiled to a .jar named JavaOCT.jar, which is placed in the Matlab working directory:
package VTK;
public class vtkVolumeView{
public int Test(){
return 10;
}
}
That is it, no other dependencies, nothing fancy. In Matlab, I try:
javaaddpath('\JavaOCT.jar'); %<-Directory and name are 100% correct
import VTK.*; %<-Package name from above
methodsview VTK.vtkVolumeView; %<-Can't find the class, argh!
Matlab kicks back that it can't find the class.
Things I've done to try and solve the problem:
Reverted to the exact same JDK as the Matlab RTE
Tried an older 1.6 JDK
Done lots of stack overflow research to try and solve it 1 2 3 4
Tried used javaclasspath and pointing to the compiled class instead
Read the Matlab documentation 5
Using clear -java after the javaaddpath
Any help would be appreciated, it is driving me nuts!
Update: Daniel R suggested just javaaddpath('JavaOCT.jar') which doesn't work either.
Final update: It finally works! I wasn't building the .jar properly. In IntelliJ, click on the project and hit F4. This brings up the Project Structure, then go to Artifacts and click the green + button and add DirectoryContent and then point to the out\production. Once this is done, as mentioned by others, it should show up in Matlab as an expandable .jar.
I don't know which operating system you are using, but the ./ seems invalid.
Try javaaddpath('JavaOCT.jar'); or javaaddpath(fullfile(pwd,'JavaOCT.jar'));.
What does exist(fullfile(pwd,'JavaOCT.jar')) return?
Some things to try:
Add the class file. When using a package, you need to add the class file in at the host of the package. For example, if your code is here:
\\full\path\to\code\VTK\vtkVolumeView.class
Then use:
javaaddpath('\\full\path\to\code')
I'm still suspicious of your *.jar path. You should usually use absolute paths when adding jar files. Try adding the results of which('JavaOCT.jar')
How did you make your jar file? Does it contain the appropriate directory structure implied by your package declaration?

search and replace text in all java files in a package

I am using a few functions in my application which i want to replace with other functions (to make it backward compatible)
My question : is it possible to find & replace some specific text in all java files in a package with some tool, or do i have to do it manually on every java file? I have a LOT of java files in the package.
For eg : i want to replace
getExternalCacheDir()
with something like
Environment.getExternalStorageDirectory + "/Android/data/<package_name>/cache/"
the IDE i'm using is Eclipse Helios. Any solutions?
Use Search - File... in Eclipse, search for getExternalCachDir() in *.java, then right click in the Search view, choose Replace All..., enter the replacement text, and click OK.
In eclipse, Just do
right click on function->Refector->Rename
or
select method + press shift+alt+R
This will change your method name through out the project.

Missing id class in R.java

I am developing an Android app using Phonegap and jQueryMobile, working in Eclipse. I want the app, with the user's permission, to auto-install a launcher icon on the user's "desktop". I've found the example LauncherShortcuts.java on Android Developers, and I am almost to the point of getting it to work. That's a big achievement, since I know extremely little of Java programming.
Almost.
This is the example code online:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html
One string or thingy in the code refuses to cooperate. Line 83...
TextView intentInfo = (TextView) findViewById(R.id.txt_shortcut_intent);
...has this constant or variable in it called "R.id.txt_shortcut_intent", and Eclipse says it doesn't recognize the id part. If I follow its suggestion of adding a class 'id' in R., it tells me there is no field txt_shortcut_intent in 'R.id'. That doesn't surprise me.
I've been able to fix a few similar errors involving R.something_or_other. But not this one. My R.java only contains the classes attr,drawable,layout, and string.
What is going on here and most importantly, what should I do to get this thing up and running? The launcher icon is all that stands between here and actually launching the app (how ironic).
If you find any errors in the project. Sometimes id of R.java entries will be shifted to string folder or R.java.
For this choose
project → clean
file → close all
click on your project
See the entries in id of R.java your ids will be in this folder
An android app uses an xml to define the layout of all the elements you want to display. In this case, you're missing an element that displays text called TextView. You don't have the Textview 'txt_shortcut_intent' defined in the xml, probably.
Here's the xml you're looking for (just copy and paste it into your main.xml):
http://developer.android.com/resources/samples/ApiDemos/res/layout/launcher_shortcuts.html
The ADT Plugin in Eclipse can only rebuild the R class if there are no (Java) errors.
Therefore, fix all errors and check if your layout ressource has the correct id (txt_shortcut_intent).
It's worth a try to clean the project and restart Eclipse.

Categories

Resources