Charset in JTextPane which using AdvancedRTFEditorKit - java

I'm having some problems with charset encodings. I'm using AdvancedRTFEditorKit (free closed source library: http://java-sl.com/advanced_rtf_editor_kit.html).
If I copy some special characters (ěščřžýáíé) from MS Word and paste them into sample delivered with AdvancedRtfEditorKit library, everything works fine. But if I do the same with my really simple SSCCE which uses AdvancedRTFEditorKit, then they appear as just rectangles. Do you know what I'm doing wrong?
This problem only occurs with MS Office products. LibreOffice works fine.
My SSCCE:
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(350, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane pane = new JTextPane();
pane.setEditorKit(new AdvancedRTFEditorKit());
frame.add(pane);
frame.setVisible(true);
}

After many changes in my code I figured out there isn't any problem with my app. My problem was just running app directly from NetBeans IDE. I don't know why, but IDE somehow encode/decode interaction with OS.

Related

jOptionPane dont show on top windows. Java 1.4

jOptionPane dont show on top windows.
I've read that using
JFrame frmOpt = new JFrame();
frmOpt.setVisible(true);
frmOpt.setLocation(100, 100);
frmOpt.setAlwaysOnTop(true);
should be enough, but the problems is that I'm using Java 1.4 and 'setAlwaysOnTop' does not exists.
so....is there a way to solve this situation?
thanks in advance.
EDIT: Here is what I'm doing:
JFrame frmOpt = new JFrame();
frmOpt.setVisible(false);
response = JOptionPane.showOptionDialog(frmOpt,message,mens, 0,JOptionPane.OK_CANCEL_OPTION,null,options,null);
First I create a JFrame, then I create a new JOptionFrame setting the JFrame.
And it still shows at the back. Notice I do not use setAlwaysOnTop because of Java 1.4

Using a custom cursor

I've searched quite a few threads here but none have helped.
I have a few JFrames and each JFrame should have its own individual cursor, symbolizing which version of the program the user is using.
These files are in /AndroidToolkit/resources. The files are all .cur files, so they're actually proper cursors and not just images.
I've tried a few methods of doing this, but I have succeeded. I've tried using ImageIO, Toolkit, and my last try was:
Cursor cCur = Toolkit.getDefaultToolkit().createCustomCursor(getClass().getResource("../resources/ImpressionCursor.cur").getFile()., null, null);
How can I do this in an easy way, which is easy for other people to understand, without me having to always comment it with 10k lines?
Thanks in advance,
Beats
This is what you need, try this code 100% works for me on Ubuntu 12.04 LTS, it should work for you too:
public static void main(String[] args) {
Toolkit toolKit = Toolkit.getDefaultToolkit();
Image pencil = toolKit.getImage("pencil.gif");
Cursor cursor = toolKit.createCustomCursor(pencil, new Point(0, 0), "Pencil");
JFrame frame = new JFrame("Cursor Test");
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setCursor(cursor);
frame.setVisible(true);
}
this is the link for the gif file click here,
I hope that helps, Salam

Applying a font to JTextArea crashes the gui?

The following code works when the font line is commented out, and no GUI appears at all when the line is included. From what I can tell its formatted properly but its crashing the GUI. What could cause this?
public class TestCode extends JFrame{
JTextArea jta;
public TestCode(){
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JPanel content = new JPanel();
jta = new JTextArea(20, 30);
jta.setFont(new Font("Courier New", Font.PLAIN, 12)); // This line crashes
content.add(jta);
add(content);
pack();
setVisible(true);
}
public static void main (String [] args){
TestCode run = new TestCode();
}
}
I'm beginning to suspect that it has something to do with my system fonts? I have installed extra fonts, perhaps that affects Java's ability to retrieve them?
EDIT:
Just to clarify, there are no errors when I run this program. The GUI never opens and the IDE gets slow and buggy as if I were running an infinite loop. The program must be terminated via the IDE (because no GUI shows to close).
It works fine for me using 1.6 and 1.7.
Some suggestions:
1) Force the EDT for your Swing app as follows:
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
TestCode run = new TestCode();
}
});
}
Further reading:Concurreny in Swing
2) Place your JTextArea in a JScrollPane, and add the scroll pane to the panel, not the text area itself:
content.add(new JScrollPane(jta));
The problem was caused by an excessive number of downloaded fonts on my system. I had previously downloaded a Font package which contained a few thousand additional fonts which caused the IDE to spend an unnecessarily long amount of time trying to find the right font I presume.
Deleting the unused additional fonts solved the problem and now this code works fine.

Minimizing the application in windows problem

I've wrote a simple application to store some text in a derby DB. I have 2 button each one creating a new inputDialog. My problem is that when I run the program on my Ubuntu PC all is well. When I run it on a windows 7 PC when the input dialog is displayed the whole thing is minimized and hidden from the user. So each time I want some input from the user he has to restore the application. And the other problem is that the program doesn't appear in the alt-tab menu too. Here is the code that I use to display the dialog:
String s = (String) JOptionPane.showInputDialog(this, "Моля въведете име:");
All help will be greatly appreciated.
I tried the following code - directly from main() via eclipse running on Windows 7 64-bit. The JFrame remains on display, even if I try otherwise.
JFrame f = new JFrame();
f.setSize(750, 500);
f.show();
JOptionPane.showInputDialog(f, "hello", "there");
System.out.println("hi");
Try this, and if you get the same result then at least we know it's a windows issue that we're dealing with rather than a Java issue.
EDIT:
After looking through your code, I found the offending line. Also as a side note, you should generally call setVisible() after you have done configuring your window. This is especially true with my code, as it would throw an exception if you try to call setUndecorated() after you have displayed the window.
Your Code:
this.setVisible(true); //This should be called after you finish configuration
device.setFullScreenWindow(this); //This is the problem!!!
Instead you should use:
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);
If you want to have your window fullscreen then use:
this.setUndecorated(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setVisible(true);

How come JLabel doesn't show underscore character?

For some reason JLabel doesn't show underscore symbol. Is there anything in particular I have to do for enabling such behavior?
Doesn't work in Windows, Linux, MacOS with Java 1.6.x
This is the code I used to see if this worked. Try running this on your machine.
import java.awt.*;
import javax.swing.*;
public class TestUnderscore
{
// Test routine.
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(new JLabel("Test_Underscore$$"));
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(450, 450);
frame.setVisible(true);
}
}
Does not work for me on Linux. Same issue for highlighted text in JTextArea. If line1 and line 2 contain underscores and both are highlighted, underscores in line 1 are not visible but underscores in line2 are. Changing alpha values of highlight color did not fix problem.
Found a fix - change the font. Both worked when I used Verdana 12pt.

Categories

Resources