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 ...)
Related
I have tried several solutions for changing the icon of my application, but none have worked! I do not get any error when i do the following but it still won't change!? Please, can someone tell me where I am going wrong because i don't see any error, and I am not receiving any error either!
I even made sure that the icon I want to use is a 20x20 pixel icon, because I read somewhere that is the maximum size for an icon.
frame.setIconImage(
new ImageIcon(getClass().getResource("/images/bfc_icon.png")).getImage());
Why is this not working? Any help would be greatly appreciated!
EDIT:
I am testing if the file exists, turns out it does but it still is not being set as the application icon...why is this??
URL url = getClass().getResource("src/images/bfc_icon.png");
if (url == null)
System.out.println( "Could not find image!" );
else
frame.setIconImage(new ImageIcon(url).getImage());
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
// TODO add your handling code here:
Image img=ImageIO.read(getClass().getResource("ur path"));
this.setIconImage(img);
} catch (IOException ex) {
}
this will work
It seems a bit too late, but I hope this helps.
This problem probably happens when you called the setIconImage() before you initialize the JFrame.
I also had this problem with the code below (w/ Eclipse IDE):
setIconImage(Toolkit.getDefaultToolkit().getImage(Apps.class.getResource("/ico.png")));
initComponents();
I accidentally solved the problem by swapping these two so it looks like this:
initComponents();
setIconImage(Toolkit.getDefaultToolkit().getImage(Apps.class.getResource("/ico.png")));
You should try to do it as well, at least call the setIconImage() after the JFrame has initialized if you didn't use any window builder tool.
Cheers!
In my case, I just simply copied the picture I want to use as my icon to the project folder and not the src folder (source code folder) and it worked.
I noticed that recently when I run my LibGDX game it takes a good 20 seconds to boot up which is strange because I'm only loading a few resources. I put breakpoints in my main method to pinpoint where the app was getting stuck, and it turns out it's getting stuck when I call this line:
new Lwjgl3Application(new GdxGame(), config);
In the Lwjgl3Application constructor, it is hanging on this method call:
initializeGlfw();
Which looks like this:
static void initializeGlfw() {
if (errorCallback == null) {
Lwjgl3NativesLoader.load();
errorCallback = GLFWErrorCallback.createPrint(System.err);
GLFW.glfwSetErrorCallback(errorCallback);
if (!GLFW.glfwInit()) {
throw new GdxRuntimeException("Unable to initialize GLFW");
}
}
}
In this method it gets stuck on createPrint and GLFW.glfwInit(). The print method looks like this:
public static GLFWErrorCallback createPrint(PrintStream stream) {
return new GLFWErrorCallback() {
private Map<Integer, String> ERROR_CODES = APIUtil.apiClassTokens((field, value) -> 0x10000 < value && value < 0x20000, null, GLFW.class);
#Override
public void invoke(int error, long description) {
String msg = getDescription(description);
stream.printf("[LWJGL] %s error\n", ERROR_CODES.get(error));
stream.println("\tDescription : " + msg);
stream.println("\tStacktrace :");
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
for ( int i = 4; i < stack.length; i++ ) {
stream.print("\t\t");
stream.println(stack[i].toString());
}
}
};
}
All of these methods come from the Lwjgl library. Does anybody know why my app might be getting stuck on these method calls?
I've had the same issue and it seams to be tied to the machine you are on. I made a clean VS15 solution with GLFW and ran it on several different PCs to find that only my desktop had this issue. I also tested the LWJGL binding of GLFW and had the same results.
[EDIT] the wait happens in the glfwInit() call
/* Initialize the library */
if (!glfwInit()) // stuck here
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(1920, 1080, "Hello World", NULL, NULL);
There is one post that I came across an archived post on the openGL forums that mentions an issue similar to this but it's fairly old and might be referring to a slightly different issue.
I can recommend to check that you are excluding your build folder from any antivirus, sometimes they see the generated executables as potential threats and thus might be slow however i dont believe that's your issue.
Sadly the only option that has worked for me was a clean install of windows, though the bug mysteriously stopped manifesting itself when I connected a VR headset and reappeared a couple days later. Hope you have better luck than me and dont have to clean install your OS and if you find a less cumbersome solution be sure to spread the word.
I'm trying to resize an existing PDF button. I want to amend the label from "Print" to "Print Amended".
PushbuttonField button = form.getNewPushbuttonFromField("HoldButton");
Rectangle box = button.getBox();
box.setRight(box.getRight() + 72); // Increase width by 1"
button.setBox(box);
button.setText("Print Amended");
form.replacePushbuttonField("HoldButton", button.getField());
The above code successfully changes the label, but not the size. The end result is a button with no change in width, and the label "Print Amended" squished together.
Is it possible to resize an existing button in iText?
I tried your example and I was surprised that I could reproduce your problem.
I looked into the iText code and I see that it is explicitly forbidden to change the /T value. This makes sense: if you want to replace an existing button, you don't want to change its name.
However, for some reason we also explicitly forbid changing the /Rect value. See the code of the AcroFields class:
for (Object element : button.getKeys()) {
PdfName key = (PdfName)element;
if (key.equals(PdfName.T) || key.equals(PdfName.RECT))
continue;
if (key.equals(PdfName.FF))
values.put(key, button.get(key));
else
widgets.put(key, button.get(key));
merged.put(key, button.get(key));
markUsed(values);
markUsed(widgets);
}
I am not sure why we made this decision when we wrote this code. If I remove || key.equals(PdfName.RECT), then your code works as expected.
As we deliberately excluded changing the dimensions of the button, I am in doubt if this is a bug or if we intentionally added that code there. Reading your requirement, I am inclined to remove || key.equals(PdfName.RECT) from the official source code.
PS: I know that this doesn't answer your question, but it does explain why your code doesn't work in spite of the fact that it looks perfectly OK. As I explained: I'm really surprised that it doesn't work, because I'm responsible for the iText code...
PS 2: I've changed the code in the official trunk.
Try something like:
newButton1 = new JButton("Print Amended") {
{
setSize(150, 75);
setMaximumSize(getSize());
}
};
or:
Try to use setMaximumSize() method
button.setMaximumSize(new Dimension(100,100));
I am using Itext to create a pdf and I cannot get the checkbox to uncheck. Here is my code:
RadioCheckField bt = new RadioCheckField(writer, new Rectangle(300, 300, 400, 400),
"check1", "Yes");
bt.setCheckType(RadioCheckField.TYPE_CHECK);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
bt.setBorderColor(BaseColor.BLACK);
bt.setBackgroundColor(BaseColor.WHITE);
bt.setChecked(false);
PdfFormField ck = bt.getCheckField();
writer.addAnnotation(ck);
You can see that the bt.setChecked(false) is in the code, but the checkbox is still checked. I looked at the docs and it seems to me that it is supposed to work this way. What do I not understand?
First this:
You've posted the same question on Nabble which is not a site endorsed by iText. See http://lowagie.com/nabble for more info.
As you were not subscribed to the official mailing-list, I had to manually approve your question. Now I see that you posted the same question here. Cross-posting is usually not appreciated in a community.
As for your question, I've answered it here: http://article.gmane.org/gmane.comp.java.lib.itext.general/65407
Bottom line: I made a Short, Self Contained, Correct (Compilable), Example based on your code and I executed it. I couldn't reproduce the problem you reported. Maybe there is no problem. Maybe there was a problem in a previous version of iText that has now been fixed.
I also read that you shipped your code with the text color set to white. I don't understand: that doesn't make sense! Your PDF will have an interactive field, but people will never be able to see whether or not it's checked...
If you don't care, if all you wanted is to show a checkbox, then using an interactive field is overkill. You should have used a check box character, for instance from the ZapfDingbats font.
If you're using the AGPL version of iText, please show me the URL where I can find your code (as you know, the AGPL requires code using AGPL software to be distributed as AGPL too).
Try the following way, for me it is working:
public void addRadioGroup() throws Exception{
if(!this.doc.isOpen()){
this.doc.open();
}
PdfFormField radioGroup = PdfFormField.createRadioButton(this.writer, false);
radioGroup.setFieldName("numbers");
for(int i=0;i<3;i++){
Rectangle rect = new Rectangle(130+(40*i), 430, 160+(40*i), 455);
this.addRadioButtonKid(radioGroup, rect,String.valueOf(i));
}
this.writer.addAnnotation(radioGroup);
}
private void addRadioButtonKid(PdfFormField radio, Rectangle rect, String onValue) throws Exception{
RadioCheckField bt = new RadioCheckField(this.writer, rect, null, onValue);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
bt.setBorderColor(Color.BLACK);
bt.setBackgroundColor(Color.WHITE);
bt.setCheckType(RadioCheckField.TYPE_CROSS);
bt.setChecked(false);
PdfFormField ck = bt.getCheckField();
ck.setPlaceInPage(1);
radio.addKid(ck);
}
The only problem I had was that the default "check style" wasn't changed. A user reported this problem back in 2011 on the mailinglist in 2011. If you need another style patch iText for yourself or use the workaround described by Mark.
Update: After 2 years they seem to have fixed the problem in the latest iText version 5.4.3 (cp. the change of Michaƫl Demey)
try using a checkbox instead of a radiobutton since you only have one
I'm having trouble getting a short MP3 file to play in a very small app I'm writing to learn how to develop for the BlackBerry.
Because I'm a newbie at BlackBerry development, I've uploaded my Eclipse project for the app to http://stroke.sampablokuper.com/stroke.zip because I don't know if the problem's with my Java programming, or the way I've laid out the resources in my project, or something else.
It's a very small project - only one Java file & three media files - so please help me by seeing if you can run it without errors in the Curve 8520 simulator on your computer. (It's designed for the 8520, because that's the phone a friend of mine has; I don't have a BB myself - yet!)
The idea is that when the user presses/scrolls "down" on the trackball/pad, a sound will be played, but currently instead of the sound, I just get an error message: javax.microedition.media.MediaException .
I've tried to debug this, but as I say, I'm a total newbie to BB development, so I don't really know how to make sense of the information I get from the breakpoints I've set.
Please can you tell me where I've gone wrong?
I really want to finish this before Christmas; please help!
Thanks in advance :)
EDIT: here's the relevant portion of the code, stripped down as much as possible:
public boolean navigationMovement(int dx, int dy, int status, int time) {
if (dx == 0 && dy == 1)// DOWN
{
makeNoise("growl");
}
return true;
}
private void makeNoise(String action) {
if (action == "growl") {
Dialog.alert("GROWL");
try
{
Player p = javax.microedition.media.Manager.createPlayer("growl.mp3");
p.realize();
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
volume.setLevel(30);
p.prefetch();
p.start();
}
catch(MediaException me)
{
Dialog.alert(me.toString());
}
catch(IOException ioe)
{
Dialog.alert(ioe.toString());
}
}
invalidate();
}
Further edit I've removed the link to download the project, since the problem did indeed appear to be with the code, and is now solved anyway.
if you have mp3 file on SDCard your URI should be file:///SDCard/<file>.mp3 but if you are playing it from application then getResourceAsStream is the answer
The problem turned out to be that the string passed to the .createPlayer method needs to be a URI.
I tried many variations along the lines file:///growl.mp3 before eventually giving up (if anyone knows the correct URI syntax for pointing to a file within a BlackBerry App, please comment!) and settling on this:
InputStream is = getClass().getResourceAsStream("growl.mp3");
Player p = javax.microedition.media.Manager.createPlayer(is,"audio/mp3");
It's a bit crufty by comparison, but at least it works!