JAVA / SWING apps, font AA / LaF KDE 4.3

Hi Everyone,
I know the title is terrible, but here is my problem:
I am using Netbeans for most of my development projects. I am very happy with it; however, the look and feel of Netbeans (and most other Java apps, such as FreeMind for example) is appalling and does not integrate into my KDE 4.3 desktop at all. I understand that you can start netbeans with certain options to change the look and feel to GTK, but the fonts still look jagged.
I followed this forum post http://bbs.archlinux.org/viewtopic.php?id=72892 and tried to set the JRE / JAVA options globally, so that all java apps start with GTK laf and AA. However, non of the methods described work / netbeans overrides them (?).
But really, the biggest problem are the ugly fonts. Java / SWING apps do not seem to recognize my KDE settings for AA and font style at all. And non of the Cl options work to fix it.
Does anyone have any tips or tricks to fix any of these issues I am having with the combination Java / Swing / KDE / NB?
Running:
Archlinux (duh)
KDE 4.3 / qt-gtk-engine
sun-jdk 1.6uX
Netbeans 6.7.1
Thanks!
KnY

I added what I knew about improving Sun java fonts to the wiki:  http://wiki.archlinux.org/index.php/Jav … _-_Sun_JRE.  You may want to try other fonts than B&H's Lucida.  See the section in the wiki article about changing the default fonts by editing 'fontconfig.properties'.

Similar Messages

  • Expandable Menu in Java Swing app

    Hello JFriends,
    is it possible to create a expandable menu in java swing app? I am thinking of something like menu in MS Visio: http://img32.imageshack.us/i/menuip.jpg/
    It works like that: When user click on a bar it expands (with nice animation) and shows containing components.
    Or maybye there are components like that?
    Thanks in advance for Your reply and please forgive me if my english is bad.
    JRegards :-)

    Yes, such constructs are possible. There isn't a pre-made component exactly like that. The NetBeans IDE has a Window - named Palette - that's very similar. The code is open source.
    You can read about Java menus here:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]

  • Java Swing apps cause Windows 2K to hang

    I have an IBM clone machine running a P4 and Windows 2k that hangs whenever I try to exit out of a window in a Java swing app. Whether the window is the main application window or a menu window instantiated by the application to be a child of the main window, does not matter. It hangs regardless. I have tried multithreaded apps and they do not cause my windows machine to hang. Neither do simple swing apps. But any multithreaded swing app causes it to hang. JEdit causes it. Forte causes it. I am running Java 1.4.1. Thanks for any help in this.

    Freezes under Java 1.4.1 with Windows
    Posted on Dec 14, 2002 - 02:57 PM by slava
    Installation This is turning into a FAQ, so I thought I'd post it on the community site. A lot of people have complained that jEdit can hard freeze their windows system after upgrading to Java 1.4.1. If you experience this, the problem is not with jEdit, but with your video driver. Updating the driver to the latest version should solve the problem; downgrading to Java 1.4.0 might also work.
    http://community.jedit.org/modules.php?op=modload&name=news&file=article&sid=190&mode=thread&order=0&thold=0

  • Running java swing apps thru telnet... [Is this possible?]

    Hi All!
    I am just wandering if it is possible to run swing applications thru telnet since everytime I run it... it returns ang error....
    Exception in thread "main" java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment
    at java.lang.Class.forName1(Native Method)
    at java.lang.Class.forName(Class.java:173)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:90)
    at at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:109).null(Unknown Source)
    at java.lang.Class.forName1(Native Method)
    at java.lang.Class.forName(Class.java:173)
    at java.awt.Toolkit$2.run(Toolkit.java:754)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:745)
    at javax.swing.ImageIcon.<init>(ImageIcon.java:226)
    at javax.swing.LookAndFeel$1.createValue(LookAndFeel.java:295)
    at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:203)
    at javax.swing.UIDefaults.get(UIDefaults.java:148)
    at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:65)
    at javax.swing.UIDefaults.getIcon(UIDefaults.java:429)
    at javax.swing.UIManager.getIcon(UIManager.java:562)
    at javax.swing.plaf.basic.BasicOptionPaneUI.getIconForType(BasicOptionPaneUI.java:600)
    at javax.swing.plaf.basic.BasicOptionPaneUI.getIcon(BasicOptionPaneUI.java:586)
    at javax.swing.plaf.basic.BasicOptionPaneUI.createMessageArea(BasicOptionPaneUI.java:337)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:146)
    at javax.swing.JComponent.setUI(JComponent.java:475)
    at javax.swing.JOptionPane.setUI(JOptionPane.java:1725)
    at javax.swing.JOptionPane.updateUI(JOptionPane.java:1747)
    at javax.swing.JOptionPane.<init>(JOptionPane.java:1710)
    at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:832)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:646)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:617)
    at JTest.main(JTest.java:40)
    Source Code:
    import javax.swing.*;
    import java.awt.*;
    public class JTest extends JFrame{
    JPanel pnlMain = new JPanel();
    JLabel lblMsg=new JLabel("This is only a test.");
    Font font=new Font("Arial", Font.BOLD, 28);
    public JTest(){
    try{
    this.setTitle("Unix Frame Testing");
    this.setBounds(10,10,500,100);
    this.setVisible(true);
    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    lblMsg.setFont(font);
    lblMsg.setBounds(100,10,250,50);                    
    pnlMain.setLayout(null);
    pnlMain.add(lblMsg);
    this.setContentPane(pnlMain);
    }catch(Exception e)
    { System.out.println("Unable to Display Window.");
    JOptionPane.showMessageDialog(null,"Unable to Display Window.","Error",JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
    public static void main(String args[]){
    JTest test=new JTest();
    }

    "scripts" are entirely different from GUI applications. What do you expect to happen when you run a Swing application through telnet on another machine? Do you expect the Swing UI to be magically transported to the local Windows machine?
    Not gonna happen. Yes, like ejp hinted, you could run an X-environment on your local machine and have the Swing UI tunnel its output there, but are you sure you want GUI apps to run on a remote machine like that? It's not gonna be fun to work with, I'll tell you that.
    Why not create a Java WebStart app (or perhaps even an applet) out of your application, so your users can run the application locally?

  • Java swing app distribution & setup

    We developed a java swing standalone app. How you guys distribute this kind app to end users if they know little about app setup(like data entry clerks).
    We like to generate an executable file bundling the app and JRE for our clients. They just run this executable to detect if there is no JRE on the local machine then install it, and then install the app and setup all environment variables. Is there any tool to do this?
    Thanks.

    If all you need to do is package the JRE with the app and install, then an installation tool like ZeroG InstallAnywhere would be a very good solution.
    If all you need to package, install and automatically deploy updates, you can probably cobble together an installer that uses Java Web Start. Note that in addition to the JRE, you will also need ensure that Web Start is installed.
    If you need to package, install, update, rollback, report, monitor, receive error alerts, and otherwise manage the application, you probably need DeployDirector, in which case, I encourage you to evaluate DeployDirector at http://www.sitraka.com/software/deploydirector/
    And yes, both InstallAnywhere and DeployDirector will allow you to deploy and manage a client-side app that communicates with a database and reads and writes from files on the client -- neither of these tools enforce the sandbox. Java Web Start will require you to either sign the application, or or use the JNLP API.
    Sonal Champsee
    [email protected]
    DeployDirector Product Manager
    Sitraka (now part of Quest Software)

  • Java Swing App hangs on socket loop

    H}ello everyone i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. I can't do that however since my app hangs when i look through the readLine() function to receive data and i dont know how to fix this error. The code is below.
    The doSocket() function is where the while loop is if anyone can help me with this i'd be very greatful.
    * GuiFrame.java
    * Created on August 13, 2008, 9:36 PM
    import java.net.*;
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author  brian
    public class GuiFrame extends javax.swing.JFrame {
        /** Creates new form GuiFrame */
        public GuiFrame() {
            initComponents();
        Socket client_sock = null;
        PrintWriter out = null;
        BufferedReader in = null;
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            convertButton = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Test Bot");
            convertButton.setText("Connect");
            convertButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    convertButtonActionPerformed(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(41, 41, 41)
                    .addComponent(convertButton)
                    .addContainerGap(42, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(convertButton)
                    .addContainerGap(26, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
    private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        if (convertButton.getText()=="Connect") {
                    String old;
                    try {
                        client_sock = new Socket("www.spinchat.com", 3001);
                        out = new PrintWriter(client_sock.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                    } catch (UnknownHostException e) {
                    } catch (IOException e) {
                try {
                    doSocket();
                } catch (IOException ex) {
                    Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        } else if (convertButton.getText()=="Disconnect") {
            out.println("e");
            out.close();
            try {
                client_sock.close();
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
    private void doSocket() throws IOException {
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String userInput;
        String old;
            while ((userInput = stdIn.readLine()) != null) {
                old = userInput;
                if (userInput != old) {
                    String proto = userInput.substring(0, 0);
                    if (proto == ":") {
                        out.println("{2");
                        out.println("BI'm a bot.");
                        out.println("aNICKHERE");
                        out.println("bPASSHERE");
                    } else if (proto == "a") {
                        convertButton.setText("Disconnect");
                        out.println("JoinCHannel");
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new GuiFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JButton convertButton;
        // End of variables declaration                  
    }Edited by: briansykes on Aug 13, 2008 9:55 PM
    Edited by: briansykes on Aug 13, 2008 9:56 PM

    >
    ..i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. >Is this intended as a GUId app? If so, I would stick to using a GUI for input, rather than reading from the command line (which when I run it, is the DOS window that jumps up in the BG - quite counterintuitive). On the other hand, if it is intended as a non-GUId or headless app., it might be better to avoid any use of JComponents at all.
    My edits stick to using a GUI.
    Other notes:
    - String comparison should be done as
    s1.equals(s2)..rather than..
    s1 == s2- Never [swallow exceptions|http://pscode.org/javafaq.html#stacktrace] in code that does not work.
    - Some basic debugging skills are well called for here, to find where the program is getting stuck. When in doubt, print out!
    - What made you think that
    a) a test of equality on a member against which you had just set the value to the comparator, would logically lead to 'false'?
    old = userInput;
    if (userInput != old) ..b) A substring from indices '0 thru 0' would provide 1 character?
    String proto = userInput.substring(0, 0);
    if (proto == ":") ..
    >
    ..if anyone can help me with this i'd be very greatful.>Gratitude is often best expressed through the offering of [Duke Stars|http://wikis.sun.com/display/SunForums/Duke+Stars+Program+Overview].
    * GuiFrame.java
    * Created on August 13, 2008, 9:36 PM
    import java.net.*;
    import java.io.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    * @author  brian
    public class GuiFrame extends JFrame {
        /** Creates new form GuiFrame */
        public GuiFrame() {
            initComponents();
        Socket client_sock = null;
        PrintWriter out = null;
        BufferedReader in = null;
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            convertButton = new JButton();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("Test Bot");
            convertButton.setText("Connect");
            convertButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    convertButtonActionPerformed(evt);
            GroupLayout layout = new GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(41, 41, 41)
                    .addComponent(convertButton)
                    .addContainerGap(42, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(convertButton)
                    .addContainerGap(26, Short.MAX_VALUE))
            pack();
            setLocationByPlatform(true);
        }// </editor-fold>
    private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {
        if (convertButton.getText()=="Connect") {
                    String old;
                    try {
                        System.out.println( "Connect start.." );
                        client_sock = new Socket("www.spinchat.com", 3001);
                        out = new PrintWriter(client_sock.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                        System.out.println( "Connect end.." );
                    } catch (UnknownHostException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                try {
                    doSocket();
                } catch (IOException ex) {
                    Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        } else if (convertButton.getText()=="Disconnect") {
            out.println("e");
            out.close();
            try {
                client_sock.close();
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
        private void doSocket() throws IOException {
            System.out.println( "doSocket start.." );
            String userInput;
            String old;
            userInput = JOptionPane.showInputDialog(this, "Send..");
            while(userInput!=null && userInput.trim().length()>0) {
                System.out.println( "doSocket loop 1.." );
                String proto = userInput.substring(0, 1);
                System.out.println("proto: '" + proto + "'");
                if (proto.equals(":")) {
                    System.out.println("Sending data..");
                    out.println("{2");
                    out.println("BI'm a bot.");
                    out.println("aNICKHERE");
                    out.println("bPASSHERE");
                } else if (proto.equals("a")) {
                    convertButton.setText("Disconnect");
                    out.println("JoinCHannel");
                userInput = JOptionPane.showInputDialog(this, "Send..");
            System.out.println( "doSocket end.." );
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new GuiFrame().setVisible(true);
        // Variables declaration - do not modify
        private JButton convertButton;
        // End of variables declaration
    }

  • Launching Swing apps in foreground remotely

    We have an agent that runs on our machines waiting to start and stop java applications, but there is a problem when the application has a GUI element to it. We are using the RunTime classes and it executes applications in the background which means that GUIs cannot be seen even though they are running.
    What is the secret to automatically launching java swing apps in the foreground?
    Thanks in advance.

    Replying to myself, as I think I've just found the answer (at least for an windows environment)
    --> Just start your app with "javaw" instead of "java"
    (What would be the right way to do it in Linux, for instance?)
    Joao Clemente

  • In program written with Java Swing, I can't input Chinese

    In program written with Java Swing, I can't input Chinese.
    But if I change my language first, then change the input method tu U.S, open the Java Swing application, finally I can input Chinese. I want to know how to fix this bug.
    My OS is Mac OS X 10.6.8.
    At the JDK version 1.6.0_29, I can input Chinese friendly in Java Swing applications. But after 1.6.0_31, I can't do it anymore. The input methods can input Chinese in other non Java Swing applications so the problem must create by JDK or JRE's Swing part. What's the different between 1.6.0_29's Swing and 1.6.0_31's ? Why ? I heard that Java Swing apps not support Chinese input methods seens 2009... Why haven't fix these yet?

    Chazza wrote:
    Perhaps you need to change your keyboard layout in Xorg?
    https://wiki.archlinux.org/index.php/Ke … ard_layout
    Thanks for your answer!
    I have tried to change the keyboard layout from "en" to "cn", but it is still not work.
    The input method coin on the righttop is right when I change the method.But it still output english even I use ibus-pinyin.There is not a box for my choosing chinese words.
    Last edited by Dilingg (2015-05-15 16:18:43)

  • Launching report from Swing app

    How do you launch a report froma Java Swing app and how does the report get viewed and then saved?
    Thanks.

    hello,
    there are several ways of running a report.
    a) by executing rwrun
    b) by submitting an HTTP request to the reports server
    c) by executing rwcli to submit a request to the reports server
    the output has to be viewed using either a browser window.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Performance issue Java Swing under Windows 7

    Hello,
    we have MDI Java Swing application running under Window7. We got a big problem with performance in MDI Windows using AERO.
    Exist any way for Java to tell Win7 that it should not use Aero??
    Thank you,
    David.
    Edited by: 969767 on 6.11.2012 3:33

    If you try to open properties dialog for application (or app shortcut) there you can see "Compatibility" tab and there is check box "Disable visual themes". If we disable this theme our java swing app is very better performance under Windows 7. We need to disable visual theme via java code, if it is possible...
    Thanks.

  • Java SE 6 update 1 swing apps run slow

    When I first installed JDK6/JRE SE 6, Netbeans 5.5 and 6 (M9) ran beautifully. All GUI Java applications were quite responsive, and I never noticed a speed issue. However, last week Netbeans started running slowly. You could practically see the entire screen being repainted from top to bottom over the course of a second or two. Naturally, this gets quite annoying when attempting to write code since everytime I scroll, I have to wait a second for the screen to repaint itself. At first I thought this was just a Netbeans issue, but I notice that every other Java GUI app also repaints very slowly. I've been trying to think back as to what could possibly have changed in my system to cause things to run slowly, but can't think of anything.
    I tried reinstalling the JDK and JRE (as well as Netbeans), but it does not seem to have fixed the issue. The reason I'm posting this under the Swing forum is because I suspect this is a Swing issue -- applications that I have written that do not utilize a GUI seem to run at the same speed as before.
    Any suggestions as to what might be causing this slowness?

    could it freezing be related to my delay in updating it ?
    Message was edited by: Sheepo39

  • A tiny font is used in many places across Java Swing applications (help!)

    In many places in Java but mostly in text boxes I'm seeing a very small font that is quite hard to read.
    I am seeing this all over the place in Java programs and it is getting on my nerves.
    I'm not sure what is causing this.
    I also encountered this issue when running Java on Windows XP.
    I really need help on how to solve this,
    Or maybe it is actually a bug with Java itself and Windows?
    An image of the problem in SwingSet2:
    [SwingSet 2 Tiny Font Example|http://img687.imageshack.us/img687/1373/swingset2tinyfont.png]
    System spec:
    Windows 7 Professional 32-bit (Aero is on)
    Java 6 Update 20
    English system locale and language
    No special dpi settings (default)
    Screen Resolution: 1280x1024
    Avast Antivirus 5.0
    An intel graphics card
    Edited by: Temp111 on May 9, 2010 7:38 AM

    camickr wrote:
    That is not a problem. Somewhere in that code the programmer uses setFont(....) to make it a smaller font. The default font of a text component does not behave like that.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org/], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.No, it's defiantly a problem. Probably in the default fonts that Swing uses in some places.
    I detected one place where I can easily trigger this issue, a JTextArea And the Windows Look and Feel, So here is a SSCCE for you:
    [Picture Of Tiny Font SSCCE With Tiny Font issue|http://img88.imageshack.us/img88/7876/tinyfont.png]
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    public class TinyFont {
         public static void main(String[] args) {
              try {
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              } catch (ClassNotFoundException e) {
                   e.printStackTrace();
              } catch (InstantiationException e) {
                   e.printStackTrace();
              } catch (IllegalAccessException e) {
                   e.printStackTrace();
              } catch (UnsupportedLookAndFeelException e) {
                   e.printStackTrace();
              JFrame frame = new JFrame("Tiny Font");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JTextArea textArea = new JTextArea("Tiny Font Test");
              frame.add(textArea);
              frame.setSize(150, 100);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
    }But I also encountered this issue in other places that use Swing.
    Try SwingSet2 Source Code Tab for example: [SwingSet2|http://java.sun.com/products/jfc/jws/SwingSet2.jnlp]

  • Font warning when running swing apps

    I am seeing this warning when I run my swing app using JRE 1.4.0.
    Any ideas on how to get fix this?
    Warning: Cannot convert string "-monotype-arial-regular-r-normal--*-140-*-*-p-*-iso8859-1" to type FontStruct
    Thanks

    As a follow up to this, it appears that you need to download OS patches to correct this problem.
    Use this as a starting point:
    http://java.sun.com/products/jdk/1.2/install-solaris-patches.html

  • How to create printable report from a swing app.

    Hi,
    I have googled quite a bit and have searched the forum extensively but haven't found answers to my questions.
    I have a small swing based application (that uses jtextfields, jbuttons, jlist, etc) that collects information from user
    and stores in some variables; which are like strings, integers, hashmap, etc.
    Now this information is to be formatted and is to be printed as a report.
    Formatted as in, some part of the collected text is to be printed in certain font and other in different color and so on.
    Also the report is to be printed on a paper leaving some space at left and at the top. That means margins need to be set.
    And before all info is to be sent to printer I need to display this information in some report viewer (preview).
    How can I format certain text and set margins? (Is there some Document kind of api which allows me to set margins, change font of certain text?)
    How should I display this text / information as a print preview? (Should I use jeditorpane / jtextpane ?)
    How should I send all the information to the printer? (What java api should be used for printing?)
    The data entered by the user is not saved / persisted to any database. It's to be sent to the printer after submit button is pressed on the swing app.
    Since there is no database I couldn't use jasper-reports.
    Following are links to all threads (not useful) I found when I searched for swing / print / report in the forum :
    http://forums.sun.com/thread.jspa?forumID=331&threadID=225351
    http://forums.sun.com/thread.jspa?forumID=57&threadID=576758
    http://forums.sun.com/thread.jspa?forumID=57&threadID=570629
    http://forums.sun.com/thread.jspa?forumID=1&threadID=489905
    http://forums.sun.com/thread.jspa?forumID=57&threadID=571093
    http://forums.sun.com/thread.jspa?forumID=257&threadID=138450
    http://forums.sun.com/thread.jspa?forumID=57&threadID=583150
    http://forums.sun.com/thread.jspa?forumID=57&threadID=5399572
    http://forums.sun.com/thread.jspa?forumID=57&threadID=579619
    http://forums.sun.com/thread.jspa?forumID=57&threadID=593199
    Help would be much appreciated.

    alan_mehio wrote:
    The simplest thing to do in your case is to load the file content into the JTextArea
    then to create the header and the footer if there is any from java.text.MessageFormat
    then you invoke the print method on the JTextArea instance object> Just let me know if you are face any furrher problem
    Alan Mehio,
    I have been able to set margins and get the printout just the way I want it (after some experiments / trial & error).
    But the problem is, parameters to paper.setImageableArea() are hard coded as in the example code below :
            System.out.println("print?");
            PrinterJob printJob = PrinterJob.getPrinterJob();
            if (printJob.printDialog()) {
                PageFormat pf = printJob.defaultPage();
                Paper paper = pf.getPaper();
                paper.setSize(8.5 * 72, 11 * 72);
                System.out.println("paper width : " + paper.getWidth());// expecting 612
                System.out.println("paper height : " + paper.getHeight());// expecting 792
                System.out.println("ImageableHeight : " + paper.getImageableHeight());
                System.out.println("imageable width : " + paper.getImageableWidth());
                System.out.println("ImageableX : " + paper.getImageableX());
                System.out.println("Imageable y : " + paper.getImageableY());
                //paper.setImageableArea(108, 144, paper.getWidth() - 108, paper.getHeight() - 144);
                paper.setImageableArea(222, 244, paper.getWidth() - 222, paper.getHeight() - 244);
                pf.setPaper(paper);
                printJob.setPrintable(jTextArea1.getPrintable(null, null), pf);
                try {
                    printJob.print();
                } catch (Exception ex) {
                    System.out.println("exception while printing...");
                    ex.printStackTrace();
            }In my case the left margin should be 1.5 inches (38.1mm) and top margin should be 2 inches (50.8 mm)
    Considering 72dpi printer for a A4 size page (8.5in X 11in), the parameters to paper.setImageableArea() should be
    (108, 144, paper.getWidth() - 108, paper.getHeight() - 144);
    But the printout leaves only 1inch for top and left margins.
    Here are o/p lines for method-call with above said params :
    paper width : 612.0
    paper height : 792.0
    ImageableHeight : 648.0
    imageable width : 468.0
    ImageableX : 72.0
    Imageable y : 72.0
    When I pass the following values I get text printed with desired margins on the paper but the above printlns remain exactly the same!
    paper.setImageableArea(222.4, 244, paper.getWidth() - 222.4, paper.getHeight() - 244);
    Although I have been able to achieve what I wanted to without using 3rd party libraries,
    I feel this hard coding of values isn't a good idea and leaves a doubt whether this will work on other systems with different printers.
    My question is, how to get these numbers correct every time? Is there a formula for obtaining these numbers?
    Also formatting of certain part of to-print text is something that is yet to be figured out.
    Thanks.

  • How to create the digital clock in java swing application ?

    I want to create the running digital clock in my java swing application. Can someone throw some light on this how to do this ? Or If someone has done it then can someone pl. paste the code ?
    Thanks.

    hi prah_Rich,
    I have created a digital clock you can use. You will most likely have to change some things to use it in another app although that shouldn't be too hard. A least it can give you some ideas on how to create one of your own. There are three classes.One that creates the numbers. a gui class and frame class.
    cheers:)
    Hex45
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class DigitalClock extends Panel{
              BasicStroke stroke = new BasicStroke(4,BasicStroke.CAP_ROUND,
                                               BasicStroke.JOIN_BEVEL);
              String hour1, hour2;
              String minute1, minute2;
              String second1, second2;
              String mill1, mill2, mill3;
              int hr1, hr2;
              int min1, min2;
              int sec1, sec2;
              int mll1, mll2,mll3;       
        public void update(Graphics g){
             paint(g);
         public void paint(Graphics g){
              Graphics2D g2D = (Graphics2D)g;
              DigitalNumber num = new DigitalNumber(10,10,20,Color.cyan,Color.black);     
              GregorianCalendar c = new GregorianCalendar();
              String hour = String.valueOf(c.get(Calendar.HOUR));
              String minute = String.valueOf(c.get(Calendar.MINUTE));
              String second = String.valueOf(c.get(Calendar.SECOND));
              String milliSecond = String.valueOf(c.get(Calendar.MILLISECOND));
              if(hour.length()==2){
                   hour1 = hour.substring(0,1);
                   hour2 = hour.substring(1,2);
              }else{
                   hour1 = "0";
                   hour2 = hour.substring(0,1);
              if(minute.length()==2){
                   minute1 = minute.substring(0,1);
                   minute2 = minute.substring(1,2);
              }else{
                   minute1 = "0";
                   minute2 = minute.substring(0,1);
              if(second.length()==2){
                   second1 = second.substring(0,1);
                   second2 = second.substring(1,2);
              }else{
                   second1 = "0";
                   second2 = second.substring(0,1);
              if(milliSecond.length()==3){
                   mill1 = milliSecond.substring(0,1);
                   mill2 = milliSecond.substring(1,2);
                   mill3 = milliSecond.substring(2,3);
              }else if(milliSecond.length()==2){
                   mill1 = "0";
                   mill2 = milliSecond.substring(0,1);
                   mill3 = milliSecond.substring(1,2);
              }else{
                   mill1 = "0";
                   mill2 = "0";
                   mill3 = milliSecond.substring(0,1);
              hr1  = Integer.parseInt(hour1);     
              hr2  = Integer.parseInt(hour2);
              min1 = Integer.parseInt(minute1);
              min2 = Integer.parseInt(minute2);
              sec1 = Integer.parseInt(second1);
              sec2 = Integer.parseInt(second2);
              mll1 = Integer.parseInt(mill1);
              mll2 = Integer.parseInt(mill2);
              g2D.setStroke(stroke);
              g2D.setPaint(Color.cyan);
              num.setSpacing(true,8);
              num.setSpacing(true,8);
              if(hr1==0&hr2==0){
                   num.drawNumber(1,g2D);
                   num.setLocation(40,10);
                   num.drawNumber(2,g2D);
              else{
                   if(!(hr1 == 0)){     
                        num.drawNumber(hr1,g2D);
                   num.setLocation(40,10);
                   num.drawNumber(hr2,g2D);
              num.setLocation(70,10);
              num.drawNumber(DigitalNumber.DOTS,g2D);
              num.setLocation(100,10);
              num.drawNumber(min1,g2D);
              num.setLocation(130,10);
              num.drawNumber(min2,g2D);
              num.setLocation(160,10);
              num.drawNumber(DigitalNumber.DOTS,g2D);
              num.setLocation(190,10);
              num.drawNumber(sec1,g2D);
              num.setLocation(220,10);
              num.drawNumber(sec2,g2D);
              /*num.setLocation(250,10);
              num.drawNumber(DigitalNumber.DOTS,g2D);
              num.setLocation(280,10);
              num.drawNumber(mll1,g2D);
              num.setLocation(310,10);
              num.drawNumber(mll2,g2D);
              g2D.setPaint(Color.cyan);
              if((c.get(Calendar.AM_PM))==Calendar.AM){               
                   g2D.drawString("AM",260,20);
              }else{
                   g2D.drawString("PM",260,20);
         String dayOfweek = "";     
         switch(c.get(Calendar.DAY_OF_WEEK)){
              case(Calendar.SUNDAY):
                   dayOfweek = "Sunday, ";
                   break;
              case(Calendar.MONDAY):
                   dayOfweek = "Monday, ";
                   break;
              case(Calendar.TUESDAY):
                   dayOfweek = "Tuesday, ";
                   break;
              case(Calendar.WEDNESDAY):
                   dayOfweek = "Wednesday, ";
                   break;
              case(Calendar.THURSDAY):
                   dayOfweek = "Thursday, ";
                   break;
              case(Calendar.FRIDAY):
                   dayOfweek = "Friday, ";
                   break;
              case(Calendar.SATURDAY):
                   dayOfweek = "Saturday, ";
                   break;
         String month = "";     
         switch(c.get(Calendar.MONTH)){
              case(Calendar.JANUARY):
                   month = "January ";
                   break;
              case(Calendar.FEBRUARY):
                   month = "February ";
                   break;
              case(Calendar.MARCH):
                   month = "March ";
                   break;
              case(Calendar.APRIL):
                   month = "April ";
                   break;
              case(Calendar.MAY):
                   month = "May ";
                   break;
              case(Calendar.JUNE):
                   month = "June ";
                   break;
              case(Calendar.JULY):
                   month = "July ";
                   break;
              case(Calendar.AUGUST):
                   month = "August ";
                   break;
              case(Calendar.SEPTEMBER):
                   month = "September ";
                   break;
              case(Calendar.OCTOBER):
                   month = "October ";
                   break;
              case(Calendar.NOVEMBER):
                   month = "November ";
                   break;
              case(Calendar.DECEMBER):
                   month = "December ";
                   break;
         int day = c.get(Calendar.DAY_OF_MONTH);
         int year = c.get(Calendar.YEAR);
         Font font = new Font("serif",Font.PLAIN,24);
         g2D.setFont(font);
         g2D.drawString(dayOfweek+month+day+", "+year,10,80);
         public static void main(String args[]){
              AppFrame aframe = new AppFrame("Digital Clock");
              Container cpane = aframe.getContentPane();
              final DigitalClock dc = new DigitalClock();
              dc.setBackground(Color.black);
              cpane.add(dc,BorderLayout.CENTER);
              aframe.setSize(310,120);
              aframe.setVisible(true);
              class Task extends TimerTask {
                 public void run() {
                      dc.repaint();
              java.util.Timer timer = new java.util.Timer();
             timer.schedule(new Task(),0L,250L);
    class DigitalNumber {
         private float x=0;
         private float y=0;
         private float size=5;
         private int number;
         private Shape s;
         private float space = 0;
         public static final int DOTS = 10;
         private Color on,off;
         DigitalNumber(){          
              this(0f,0f,5f,Color.cyan,Color.black);          
         DigitalNumber(float x,float y, float size,Color on,Color off){
              this.x = x;
              this.y = y;
              this.size = size;
              this.on = on;
              this.off = off;
         public void drawNumber(int number,Graphics2D g){
              int flag = 0;
              switch(number){
                   case(0):          
                        flag = 125;
                        break;
                   case(1):
                        flag = 96;
                        break;
                   case(2):
                        flag = 55;
                        break;
                   case(3):
                        flag = 103;
                        break;
                   case(4):
                        flag = 106;
                        break;
                   case(5):
                        flag = 79;
                        break;
                   case(6):
                        flag = 94;
                        break;
                   case(7):
                        flag = 97;
                        break;
                   case(8):
                        flag = 127;
                        break;
                   case(9):
                        flag = 107;
                        break;
                   case(DOTS):
                        GeneralPath path = new GeneralPath();
                        path.moveTo(x+(size/2),y+(size/2)-1);
                        path.lineTo(x+(size/2),y+(size/2)+1);
                        path.moveTo(x+(size/2),y+(size/2)+size-1);
                        path.lineTo(x+(size/2),y+(size/2)+size+1);
                        g.setPaint(on);
                        g.draw(path);     
                        return;
              //Top          
              if((flag & 1) == 1){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath Top = new GeneralPath();
              Top.moveTo(x + space, y);
              Top.lineTo(x + size - space, y);
              g.draw(Top);
              //Middle
              if((flag & 2) == 2){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath Middle = new GeneralPath();
              Middle.moveTo(x + space, y + size); 
              Middle.lineTo(x + size - space,y + size);     
              g.draw(Middle);
              //Bottom
              if((flag & 4) == 4){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath Bottom = new GeneralPath();
              Bottom.moveTo(x + space, y + (size * 2));  
              Bottom.lineTo(x + size - space, y + (size * 2));
              g.draw(Bottom);
              //TopLeft
              if((flag & 8) == 8){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath TopLeft = new GeneralPath();     
              TopLeft.moveTo(x, y + space);
              TopLeft.lineTo(x, y + size - space);          
              g.draw(TopLeft);
              //BottomLeft
              if((flag & 16) == 16){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath BottomLeft = new GeneralPath();     
              BottomLeft.moveTo(x, y + size + space);
              BottomLeft.lineTo(x, y + (size * 2) - space);
              g.draw(BottomLeft);
              //TopRight
              if((flag & 32) == 32){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath TopRight = new GeneralPath();     
              TopRight.moveTo(x + size, y + space);
              TopRight.lineTo(x + size, y + size - space);
              g.draw(TopRight);
              //BottomRight
              if((flag & 64) == 64){
                   g.setPaint(on);
              }else{
                   g.setPaint(off);
              GeneralPath BottomRight = new GeneralPath();     
              BottomRight.moveTo(x + size, y + size + space);
              BottomRight.lineTo(x + size, y + (size * 2) - space);
              g.draw(BottomRight);
         public void setSpacing(boolean spacingOn){
              if(spacingOn == false){
                   space = 0;
              else{
                   this.setSpacing(spacingOn,5f);
         public void setSpacing(boolean spacingOn,float gap){
              if(gap<2){
                   gap = 2;
              if(spacingOn == true){
                   space = size/gap;
         public void setLocation(float x,float y){
              this.x = x;
              this.y = y;
         public void setSize(float size){
              this.size = size;
    class AppFrame extends JFrame{
         AppFrame(){
              this("Demo Frame");
         AppFrame(String title){
              super(title);
              setSize(500,500);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

Maybe you are looking for

  • IWeb gallery - I can't see it!

    Hello, Just finished putting together a website for my brother but having issues with the gallery. I have a portfolio page for his photos. When I'm in iweb the photo album covers scroll nicely between images and link straight to the photo gallery pag

  • Selection screen error message question

    On a selection screen, I have a selection-options for kunnr. If the user enters other than 100001 or 100002 or 100003 for this field, I want to display a error message. How do you do that? Can you please provide a sample code for this? Thanks a lot.

  • US PY HSA Benefit Plan Calc

    Friends, i am looking for suggestions on HSA Plan. Deduction for this works as FSA with deduction mdoel setup, but SAP recommends to have HSA in IT169 . For Savings Plan we cannot assign Deduction Model. Anyone with such experience in past, is there

  • Audigy 2 ZS won't play Sound from Front speakers, just Rear

    ;? ? I recently installed Windows 7, and have been having trouble with my speakers playing correctly. Intially, the first time I installed the 07/3/09 drivers from Creative, I could only play music/test sounds out of my front 2 speakers. I unistalled

  • Log in to e-mail

    Fair enough that they have changed things around, but what is annoying is having to re-enter your username & password to access your mail. I don't mind entering the "Password" but if you make one tiny mistake in your username or password, it re-sets