I'm trying to initize a TextButton by giving it a JSON file which contains the style of the button, however I keep getting the following error:
Exception in thread "LWJGL Application"
java.lang.IllegalArgumentException: Missing LabelStyle font.
After researching what the error was about, it seems that this message shows up when you forget to include a font as part of the TextButtonStyle, however i do include that in my JSON file, so i don't know why it keeps showing.
Here's my json file
{
"com.badlogic.gdx.graphics.Color":{
"golden":{"r":255,"g":215,"b":0,"a":1}
},
"com.badlogic.gdx.graphics.g2d.BitmapFont": {
"arcade": {"file": "arcade.fnt"}
},
"com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
"default": {
"font": arcade,
"fontColor": golden
}
},
"com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
"buttonstyle1": {
"up": "unpressedtextbutton",
"down": "pressedtextbutton",
"font": arcade
}
}
}
and in the code I initialize the button like this:
Skin skin = new Skin(Gdx.files.internal("buttonstyles.json"),new TextureAtlas(Gdx.files.internal("uistuff.atlas")));
myTextButton = new TextButton("text of the button",skin,"buttonstyle1")
My theory is that somehow it is not reading the font file "arcade.fnt", i'm assuming that the directory it reads the files from is the assets folder, and that's where my "arcade.fnt" file is located.
i'm sorry it seems like i made a stupid mistake. Since i declared the font in the JSON file, i erased the font i was previously using in the code to define the button styles, and there was a usage of that font later for a label style, so, it was found to be null and it gave the error.
Is it working like this? The official uiskin.json does it like this:
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: { font: default-font, fontColor: white }
}
No quotes are needed at all not even for the font.
com.badlogic.gdx.graphics.g2d.BitmapFont: {
default-font: { file: default.fnt }
},
Might not be proper JSON but libgdx has it's own lightweight JSON style.
Related
There is a button for picking time using timepickerdialog. I want to set the error when time is not selected. I tried these codes below. The error occurs but after picking time, it still appears. I need help
if (TextUtils.isEmpty(btnDate.getText().toString())) {
btnDate.setError("Bu alan boş olamaz");
btnDate.requestFocus();
return false;
}
You may use android:drawableEnd="#drawable/ic_prompt_icon" and put come prompt error to show he is missing some in order to process.
OR
Programatically you add this error icon in button on your error condition.
Drawable img = getContext().getResources().getDrawable( R.drawable.ic_prompt_icon);
txtVw.setCompoundDrawablesWithIntrinsicBounds( null, null, null, img);
If you using setError() in order to remove error when user choose correct option than make btnDate.setError (null); as by doing this it will disappear this error.
You may use Toast or Snackbar for showing errors & suggestions in your app.
Can you try this, please:
if (TextUtils.isEmpty(btnDate.getText().toString())) {
btnDate.setError("Bu alan boş olamaz");
btnDate.requestFocus();
} else {
btnDate.setError("")
// Some actions what you need
}
I cannot create an image in any of my JavaFX projects using the following kind of code:
final String url = "line.jpg";
Image image = new Image(Config.class.getResourceAsStream(url));
because there is always a null pointer exception pointing to the second line. Obviously, I have checked that the image file is in the correct directory. I have tried example programs, some directly copied from these boards, but these also fail for the same reason.
I suspect I lack a resource in Netbeans or JavaFX but I can't figure out what is missing.
The only workaround appears to be to include the image file in a css stylesheet and link it to the program by setting the gui components id like this:
Button homeButton = new Button();
homeButton.setId("homebutton");
In the stylesheet there is:
#homebutton {
-fx-background-image: url("images/homebtn.jpg");
-fx-pref-width: 30;
-fx-pref-height: 30;
}
Its not ideal being forced into this solution and Swing seems far better at dealing with image files. I assume a bug in JavaFX that always causes the following to fail:
Image image = new Image(Config.class.getResourceAsStream(url));
I want to define the background of TextButton with uiskin.json.
Here is what i tried but didn't work:
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
img: { file: bg.png }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: { down: default-round-down, up: img, font: default-font, fontColor: white }
}
So I want to make bg.png as the default background. How can i do it?
Skin cannot read file locations from the json. If you followed tutorials for Skin, you probably instantiated it with a TextureAtlas like this:
skin = new Skin(skinFilePath, textureAtlas);
When you load it like that, all the images in the json must be available by their names in the TextureAtlas.
Normally, you need all your images to be in a single TextureAtlas, for performance reasons. So the best solution would be to add this bg.png image into your TextureAtlas, and then you can refer to it by its TextureAtlas name.
If you must load it as a separate file, then you must manually load it before loading your skin.
Texture bgTexture = new Texture("bg.png");
skin = new Skin(); //empty constructor causes it not to load yet.
skin.add("bg", bgTexture);
skin.addRegions(textureAtlas); // you will be responsible for disposing the atlas separately from the skin now.
skin.load(skinFilePath);
I'm developing application which prints using Bixolon SPP-R300 mobile printer via Bluetooth.
I've managed to make the Bluetooth connection, print Text and do lineFeed but i still don't know how to print images.
For the text i have this working:
returnValue = mBxlService.PrintText("Text Example",
BxlService.BXL_ALIGNMENT_LEFT,
BxlService.BXL_FT_DEFAULT,
BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);
The mBxlService have a method for image too (mBxlService.PrintImage).
I want to print a image from the drawable folder in the project. Something like drawable/image.png
Someone have worked with this printer or know how to print images with it? There is few information about this, and i'm really trying here.
Other thing is, every time i connect the printer to android a pairing request happens, there is something to bypass that? to do that by code?
This is the printer: Bixolon SPP-R300
Thanks in advance and sorry for my language, English is not my main language.
Take a look at this link (it has a snipped of code to print image)
Android print image using BIXOLON SPP-R300
And here is the how you can get URI to your resource:
how to get an uri of an image resource in android
So, overall code will look something like this:
Uri picturePath = Uri.parse("android.resource://your.package.name/" + R.drawable.image_1);
mBxlService = new BxlService();
mBxlService.Connect();
if (mBxlService.GetStatus() == BxlService.BXL_SUCCESS) {
returnValue = mBxlService.PrintImage(picturePath.toString(),
384,
BxlService.BXL_ALIGNMENT_CENTER,
40);
if (returnValue == BxlService.BXL_SUCCESS) {
returnValue = mBxlService.LineFeed(2);
}
}
Sure, you need to replace "your.package.name" and R.drawable.image_1.
Also, there is a chance that it won't like a path to resources. In such case, I would recommend to spit the image out to SD card and print it from there.
I've run into a situation:
XSLFSlide xslfSlide = ppt.createSlide();
for (XSLFShape shape : xslfSlide) {
if (shape instanceof XSLFTextShape) {
//some code here
} else if(shape instanceof XSLFPictureShape) {
//some code here
}
}
if I have a shape type XSLFPictureShape(simply saying - picture) it throws me an Exception:
java.lang.IllegalArgumentException: Unsupported shape: org.apache.poi.xslf.usermodel.XSLFPictureShape
Is there any way to remove an image from a slide?
After amanteaux raised a bug report, I've fixed this in r1717018
After reading the comments, I've also added the missing table remove code in r1717087
As for an answer, it's generally better to raise a bug at the projects issue tracking system than hoping that someone of a projects checks the posts at SO.
(I've stopped to track/answer SO posts, as I mostly got votes for no-brainers and not for stuff I worked several days/weeks ...)