New Swing Component for Swing Palette in NetBeans

Hi guys,
I want to write a new Swing component (Bean) for drawing vertical and horizontal lines to use with netBeans GUI designer.
Could anyone direct me to a tutorial
thanks in advance

JTextcomponent.

Similar Messages

  • Swing component for awt.canvas

    Hi,
    Can anyone tell me the equivalent SWING component for awt CANVAS. I need it because i need to display only Images (nothing else) on it. If anyone can tell how I can do it.

    JPanel is the Swing-equivalent of java.awt.Canvas, but if you are just displaying images, you can use the JLabel class, which supports use of images as icons (see also ImageIcon class).
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • Swing Component for viewing huge text file

    i need to view (only view not edit) a huge text file (3 mb)
    jtextarea is for small files i need somthing else

    What error are you getting?
    I was able to bring in a 7MB text file into a JTextArea without problems. It took a while (about 15 seconds), but it still loaded.

  • How to create new SW component for custome development?

    We are looking to develop custom webdynpros and need to create our own SW components. 
    I've tried to define them in the SLD that the NWDI is connected to and when creating the tracks for the custom development, I do not see our new defined SW when trying to add the SW component to the track.
    Any ideas?  Are we going about this the wrong direction?
    Thanks!!

    Once you add component in SLD if you want to add that component to your track ,there will be a button Update CMS in domain data or track data .click that and it will refresh and fetch your newly created component.then go ahead and add component to your track
    reward points if helpful

  • File Chooser Component for JavaFX not available?

    Is there a way to have a “File Chooser Component” for JavaFX Applications?
    Netbeans IDE offers a “Palette Swing Windows” Components, displays such item, but I am unable to put it into my FX Script.
    Any workaround? or miss I a anything?
    I want to pickup any sourcefile: "{__DIR__}sound/{soundName}" from local disc and run it on a Mediaplayer

    import javax.swing.filechooser.FileFilter;
    * @author Pawel
    public class OpenFileFilter extends FileFilter {
        override public function getDescription() : String {
            return "all movies";
        override public function accept(f: java.io.File) : Boolean {
            return f.isDirectory()
                or f.getName().endsWith(".avi")
                or f.getName().endsWith(".mov")
                or f.getName().endsWith(".flv");
    import java.awt.SystemTray;
    import java.awt.TrayIcon;
    import java.awt.Toolkit;
    import java.awt.PopupMenu;
    import java.awt.MenuItem;
    import java.awt.AWTException;
    import java.lang.System;
    var stage : Stage = Stage {
        title: "JavaWars"
        width: 800
        height: 600
        scene: scene,
        style: StageStyle.TRANSPARENT,
        extensions: [
            AppletStageExtension {
                shouldDragStart: function(e): Boolean {
                    return inBrowser and e.primaryButtonDown and header.hover;
                onDragStarted: function() {
                    inBrowser = false;
                    addTray();
                onAppletRestored: function() {
                    inBrowser = true;
                    removeTray();
                useDefaultClose: true
    var trayIcon : TrayIcon;
    function addTray() : Void{
        if(SystemTray.isSupported()) {
            var tray : SystemTray  = SystemTray.getSystemTray();
            var image : java.awt.Image = Toolkit.getDefaultToolkit().getImage("{__DIR__}resources/images/trayicon.png");
            var popup : PopupMenu = new PopupMenu();
            var item : MenuItem = new MenuItem("Zakończ");
            item.addActionListener(ActionListener{
                override public function actionPerformed(e : ActionEvent): Void {
                    var tray : SystemTray  = SystemTray.getSystemTray();
                    tray.remove(trayIcon);
                    stage.close();
            popup.add(item);
            trayIcon = new TrayIcon(image, "kliknij prawym, aby zamknać aplikację", popup);
            try {
                tray.add(trayIcon);
            } catch (e : AWTException) {
                System.err.println("Can't add to tray");
        } else {
            System.err.println("Tray unavailable");
    function removeTray() : Void{
        if(SystemTray.isSupported()) {
            var tray : SystemTray  = SystemTray.getSystemTray();
            try {
                tray.remove(trayIcon);
            } catch (e : AWTException) {
                System.err.println("Can't remove tryicon");
    }

  • Support for Multilingual Numeral Input in JTextField swing component

    When the User Locale is changed from the regional & language options in the control panel and the standard digits are customized to a non Latin character set, all the windows applications adhere to the changes made. HTML also respects the changes in effect and displays any numeric values using the new character set, which are the national digits for many Eastern Locales such as Chinese, Arabic(Saudi Arabia), Urdu and many more. The JTextField swing component given by java, however, does not show any support to the new settings. Any numeric input is displayed in the Latin character set even when the input locale of the system is also changed respectively. Any text input for this case is correctly displayed in the desired literals and appropriate glyphs. However, unlike the AWT components, numeral input and display is not catered as per the user/developer's requirements. This behavior was first noticed in 2007, as far as i have found out, and was reported once again on the same thread in 2010. The thread is given below as a reference. No action or response has been taken. Kindly look into this matter and please let me know if this bug has been reported before and if there is any intent of providing a fix for it.
    Reference: http://www.coderanch.com/t/344075/GUI/java/Multilingual-support-JTextField
    Regards,
    Aitzaz Ahmad
    Software Engineer
    SENSYS

    I too had an itch to reply with something like this
    This is a sign of work well done!
    The WD has so strong UI abstraction, that hides client-server nature applications almost completely. If you search forum, you will even find posts where developers try to upgrade value of ProgressMeter in <b>for</b> loop )
    VS

  • New: awt is covering my swing component...

    i am using both awt and swing component on the same page. They are a List and a JComboBox.
    while the JcomboBox is placed above the List. it works fine but when i click on the JComboBox, the pull down menu is covered by the awt List. I know that using JList can solve the problem, but i'm new to swing and i just want to make the smallest change to my code.
    can i use layeredpane to help?

    here is a link to the Swing tutorial that mentions this problem:
    http://java.sun.com/docs/books/tutorial/uiswing/start/swingIntro.html#awt
    The Swing tutorial also has a section on converting from AWT to Swing. You should look at that.
    Here is another article from the Swing Connection titled "Mixing Heavy and Light Components"
    http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
    Like the previous post says, you are better off not to mix the two.

  • When, where, and how is a GUI event created for a Swing component?

    Somebody please help me with this issue !
    Heavy weight (AWT) components such as JFrame, JDialog, JApplet, and JWindow have
    native peers. As I understand, the senario of event creation for such heavy components
    is something like follows:
    1. A mouse click happens in a heavy component.
    2. The native platform (i.e. the OS) captures the mouse click event and
    store it as a native event somewhere in the system.
    3. java.awt.EventDispatchThread gets this message and translates the native message
    into an AWTEvent. When creating the AWTEvent, AWT actually looks up a hashtable
    for the reference to the heavy component from the reference to the native window.
    The hashtable stores all the pairs of heavy components and their native peers ever
    created during the session. Now the AWTEvent includes a reference to the "source"
    component that generates the event.
    4. java.awt.EventDispatchThread dispatches the AWTEvent to the heavy component
    for furture processing.
    As for light weight (Swing) components such as JButtion, no native peers are attached.
    So, there is no mapping from native peers to light weight components.
    After a mouse click happens over a JButton, how, when, and where is the corresponding
    event created and finnally routed to JButton. Could somebody give a sketch of the
    senario? Thanks a lot.

    Basically for Swing components, it would have to figure out based on the size and location of the components which one the click happens in. One could simply know that this panel is so big and it has such and such components in it which are however big and located at whatever point. It's a matter of digging down through components to find the lowest (or would it be highest) one.

  • Problem in Swing Component (JComboBox)

    Hello i've got one amazing problem in my Swing Component (JComboBox) while testing for Glasspane..
    Please check this photo http://www.flickr.com/photos/39683118@N07/4483608081/
    Well i used Netbeans Drag n Drop Swing so the code might be messing..any way my code looks like this:
    My code looks like this:
    public class NewJPanel extends javax.swing.JPanel {
        /** Creates new form NewJPanel */
        public NewJPanel() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jComboBox1 = new javax.swing.JComboBox();
            jCheckBox1 = new javax.swing.JCheckBox();
            setOpaque(false);
            jTextField1.setText("jTextField1");
            jLabel1.setText("jLabel1");
            jLabel2.setText("jLabel2");
            jLabel3.setText("jLabel3");
            jButton1.setText("jButton1");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            jComboBox1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            jComboBox1.setNextFocusableComponent(jCheckBox1);
            jComboBox1.setOpaque(false);
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
            jCheckBox1.setText("jCheckBox1");
            jCheckBox1.setOpaque(false);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(119, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3))
                    .addGap(51, 51, 51)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBox1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(115, 115, 115))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(70, 70, 70)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addGap(15, 15, 15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jCheckBox1))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addComponent(jButton1)
                    .addContainerGap(93, Short.MAX_VALUE))
            jComboBox1.getAccessibleContext().setAccessibleParent(null);
        }// </editor-fold>
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration
    }

    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.

  • Need advise on selecting the IDE for swing UI development

    Hi,
    I'm looking for a best IDE for developing swing application.
    Our application is a Rich Desktop Client Application which will have more than one hunderd screens. And all the business logics will be J2EE EJB services.
    At the initial stage, we thought of using the .net winform technology as Desktop Rich GUI for its best look & feel and productivity perspective, by invoking the business services thru webservices.
    But later, we decided to use swing components which are somewhat promising now-a-days. This will avoid the multi-platform issues, maintainability and perfomance difficulties.
    I would be so much grateful, if somebody could share me their experience on deciding the IDE which would be the best for Swing development currently.
    If any one has the list of different swing UI builder IDE and the feedback list correspondingly, could you post them?
    ..Thiruppathy.R

    Thanks All!!
    I experienced both NetBeans and Eclipse recently. I did not work in-depth in any of these IDEs for swing application. All the observations are from my first impression on them.
    Please find the below are my feedback on both of these IDEs from my experience in the swing application development perspective :
    Net Beans
    Advantages:
    1. Palette Manager option is good -> I can add the custom components to the palette very easily and make them available to use them readily.
    2. IDE Layout / Framework is impressive -> In the swing design mode, the palette, properties, inspector and source all are evenly arranged in a way that things can be managed smoothly. It's very impressive.
    3. Swing Components Alignment options are good -> IDE is very smart in arranging the swing components in the Panel or Frame. Even it helps the user by showing the alignment lines in the background. So we can definitely say that Net Beans has come in much better shape.
    Disadvantages:
    1. I am not allowed to change the generated code in the IDE.
    2. I can't change the component name or event method name, other than the IDE generated one.
    3. Additional Design codes will be reflected only at the runtime, but not at the design time. Here the developer is loosing the flexibility of using the code changes that impact the design.
    Eclipse - Visual Editor
    Advantages:
    1. Source and Design mode, both can be viewed simultaneously.
    2. Source and design, both are in sync all the time. The user have the complete control with the code.
    3. As everyone knows, the IDE is very powerful and ease of use.
    Disadvantages:
    1. I can't add any custom components to the palette to make it available for ready use. Only option is 'Choose Bean' to add the custom components. So I should remember the component name everytime while adding in the panel / frame.
    I also tried few commercial plugins with Eclipse. Given below is my feedback from my experience,
    1. Eclipse - JFormDesigner
    Advantage:
    1. It provides Palette Manager option and very smart in the swing components alignment settings.
    DisAdvantages:
    1. For the design mode, it uses JFD file and later java code will be generated from this JFD file. So what you are seeing in the design mode is JFD file, not our java source. Developer have no option to see the source changes in the design mode.
    2. It is a commercial product.
    2. Eclipse -> Jigloo
    Advantage:
    1. Easy to use.
    2. Custom swing components can be added the Palette.
    Disadvantage:
    1. It is similar to Eclipse - Visual Editor, but the difference is in the look and feel of the palette and event handlings.
    2. For commercial purpose, you have to purchase it.
    I also tried the JBuilder, but seems that it provides the Eclipse - Visual Editor for Swing Application development.
    I didn't try the IntelliJ IDE yet, for swing application development. Some of the forum responses tells that IntelliJ IDE is very powerful, but not recommended for swing application development.
    Eclipse - Visual Editor is promissing and it's open source. As I'm beginner to the swing development, I might have some short vision on some of the above said items.
    If somebody have a better comparison sheet and could share with us, I would be grateful.
    ..Thiruppathy.R

  • Listen for an events for Swing objects in a separate class?

    Hi all, sorry if this is in the wrong section of the forum but since this is a problem I am having with a Swing based project I thought i'd come here for help. Essentially i have nested panels in separate classes for the sake of clarity and to follow the ideas of OO based development. I have JPanels that have buttons and other components that will trigger events. I wish for these events to effect other panels, in the Hierachy of my program:
    MainFrame(MainPanel(LeftPanel, RightPanel, CanvasPanel))
    Sorry I couldnt indent to show the hierarchy. Here LeftPanel, RightPanel and CanvasPanel are objects that are created in the MainPanel. For example i want an event to trigger a method in another class e.g. LeftPanel has a button that will call a method in CanvasPanel. I have tried creating an EventListner in the MainPanel that would determine the source and then send off a method to the relevant class, but the only listeners that respond are the ones relevant to the components of class. Can I have events that will be listened to over the complete scope of the program? or is there another way to have a component that can call a method in the class that as an object, it has been created in.
    Just as an example LeftPanel has a component to select the paint tool (its a simple drawing program) that will change a color attribute in the CanvasPanel object. Of course I realize i could have one massive Class with everything declared in it, but I'd rather learn if it is possible to do it this way!
    Thanks in advance for any help you can offer
    Lawrence
    Edited by: insertjokehere on Apr 15, 2008 12:24 PM

    Thanks for the response, ive added ActionListneres in the class where the component is, and in an external class. The Listeners work inside the class, but not in the external class
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class LeftPanel extends JPanel implements ActionListener {  
        /* Constructing JButtons, null until usage of the constructor */
        JButton pencilBut;
        JButton eraserBut;
        JButton textBut;
        JButton copyBut;
        JButton ssincBut;
        JButton ssdecBut;
        ActionListener a = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.print("\nNot supported yet.");
        /* The Top Panel contains the title of program */
        public LeftPanel(Dimension d){
            /* Sets up the layout for the Panel */
            BoxLayout blo = new BoxLayout(this,BoxLayout.Y_AXIS);
            this.setLayout(blo);
            /* Sets Up the Appearance of the Panel */
            this.setMinimumSize(d);
            this.setBackground(Color.RED);
            this.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            /* Pencil Tool */
            pencilBut = new JButton("Pencil");
            pencilBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            pencilBut.setActionCommand("pencil");
            pencilBut.addActionListener(a);
            this.add(pencilBut);
            /* Eraser Tool */
            eraserBut = new JButton("Eraser");
            eraserBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            eraserBut.addActionListener(a);
            this.add(eraserBut);
            /* Text Tool */
            textBut = new JButton("Text");
            textBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            textBut.addActionListener(a);
            this.add(textBut);
            /* Copy Previous Page */
            copyBut = new JButton("Copy Page");
            copyBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            copyBut.addActionListener(a);
            this.add(copyBut);
            /* Stroke Size Increase */
            ssincBut = new JButton("Inc");
            ssincBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssincBut.addActionListener(a);
            this.add(ssincBut);
            /* Stroke Size Decrease */
            ssdecBut = new JButton("Dec");
            ssdecBut.setAlignmentX(Component.CENTER_ALIGNMENT);
            ssdecBut.addActionListener(a);
            this.add(ssdecBut);
            System.out.print("\nLeftPanel Completed");
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nAction Performed");
        }But this is not picked up in my external class here
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    public class MainPanel extends JPanel implements ActionListener {
        /* Creates a new the main JPanel that is used in the FlipBookFrame to contain all of the elements */
        public MainPanel(){
            /* TopPanel constraints*/
            tpcs.gridx = 1;
            tpcs.gridy = 0;
            tpcs.gridwidth = 1;
            tpcs.gridheight = 1;
            tpcs.fill = GridBagConstraints.BOTH;
            tpcs.weightx = 0.0;
            tpcs.weighty = 1.0;
            /* LeftPanel Constraints*/
            lpcs.gridx = 0;
            lpcs.gridy = 0;
            lpcs.gridwidth = 1;
            lpcs.gridheight = 3;
            lpcs.fill = GridBagConstraints.BOTH;
            lpcs.weightx = 1.0;
            lpcs.weighty = 1.0;
            /* CentrePanel Constraints*/
            cpcs.gridx = 1;
            cpcs.gridy = 1;
            cpcs.gridwidth = 1;
            cpcs.gridheight = 1;
            cpcs.fill = GridBagConstraints.NONE;
            cpcs.weightx = 0.0;
            cpcs.weighty = 0.0;
            /* RightPanel Constraints*/
            rpcs.gridx = 2;
            rpcs.gridy = 0;
            rpcs.gridwidth = 1;
            rpcs.gridheight = 3;
            rpcs.fill = GridBagConstraints.BOTH;
            rpcs.weightx = 1.0;
            rpcs.weighty = 1.0;
            /* BottomPanel Constraints*/
            bpcs.gridx = 1;
            bpcs.gridy = 2;
            bpcs.gridwidth = 1;
            bpcs.gridheight = 1;
            bpcs.fill = GridBagConstraints.BOTH;
            bpcs.weightx = 0.0;
            bpcs.weighty = 1.0;   
            this.setLayout(gblo);   //Sets the Layout of the panel to a GridBagLayout
            this.add(tp, tpcs); //Adds the TopPanel to the MainPanel using the TopPanel layout
            this.add(lp, lpcs); //Adds the LeftPanel to the MainPanel using the LeftPanel layout
            this.add(cp, cpcs); //Adds the CanvasPanel to the MainPanel using the CanvasPanel layout
            this.add(rp, rpcs); //Adds the RightPanel to the MainPanel using the RightPanel layout
            this.add(bp, bpcs); //Adds the BottomPanel to the MainPanel using the BottomPanel layout
            gblo.layoutContainer(this); //Lays Out the Container
        public PanelSizes getPanelSizes(){
            return ps;
        public void actionPerformed(ActionEvent e) {
            System.out.print("\nExternal Class finds event!");
            /*String command = e.getActionCommand();
            if (command.equals("pencil")){
                System.out.print("\nYESSSSSSSSSSSSSSSSSSSSS!");
        /* Create of objects using the PanelSizes funtions for defining the */
        PanelSizes ps = new PanelSizes();   //Creates a new PanelSizes object for sizing the panel
        CanvasPanel cp = new CanvasPanel(ps.getCentrePanelDimension()); //Creates a new Canvas Panel
        TopPanel tp = new TopPanel(ps.getHorizontalPanelDimension()); //Creates the TopPanel
        BottomPanel bp = new BottomPanel(ps.getHorizontalPanelDimension()); //Creates the BottomPanel
        LeftPanel lp = new LeftPanel(ps.getVerticalPanelDimension()); //Creates the LeftPanel
        RightPanel rp = new RightPanel(ps.getVerticalPanelDimension());   //Creates the RightPanel
        /* I have chosen to create individual constraints for each panel to allow for adding of all
         components a the end of the constructor. This will use slightly more memory but gives clarity
         in the code */
        GridBagConstraints cpcs = new GridBagConstraints();
        GridBagConstraints tpcs = new GridBagConstraints();
        GridBagConstraints bpcs = new GridBagConstraints();
        GridBagConstraints lpcs = new GridBagConstraints();   
        GridBagConstraints rpcs = new GridBagConstraints();
        GridBagLayout gblo = new GridBagLayout();
    }Any help will be greatly appreciated :-)

  • Opinion: new Package for every new custom Component?

    Hi there,
    I am just thinking of some possibilities to structurize my Components I made.
    I wonder if it is useful/good programming to define a new package for each new custom Component?
    So if I define a new MyComponent class extending JFrame should I make a new package:
    "mycomponent"
    containing these subfolders:
    "view"
    "model"
    "controler"
    subfolging "controler" in:
    "listeners"
    "adapters"
    "events"
    Is there any sense to do so? I think this would be the best way to structurize one's components.
    But if you do, you have to include millions of packages if you want to use one of these components :(.
    Please post, what you think.
    Thank you
    Sincerely
    Karlheinz Toni

    nope ;). I would most certainly not want to put every file in a single directory.
    But I like sturctured things. If things belong to each other, it should be visible at once, that they have something to to with each other. And the best method I can figure you is putting them in one package.
    The subpackages should be created, because of the model, that is used for all swing componentd (UI-delegete, MVC...) so that each structural component is where it belongs to.
    I don't like it if tere are 100 events one object could possibly create and you don't know the events from the component (of course you can guess by the name Event :)), but if they are in the same package, you would have to scroll a long way to get the thing you want (either m, v or c).
    So this is why I would do it ;).
    Anyway: do includes make the program run slower (I have read many threads about it, but there are way to many opinions, so I would be grateful if you post your opinions here, thx ;).
    Thanks for your answer,
    Sincerely
    Karlheinz Toni
    p.s.: why wouldn't you put them in a seperate directory (just overkill?), would you use classes that are structured like this if you are looking for a implementation of something and find it in this structure?

  • Swing component fires an event to non-GUI code

    Hi all -- this is my first post in forums.sun.com.
    Question to get me started -
    I have a Swing component that fires an ActionEvent. I would like that ActionEvent to trigger code that does not run on the AWT Event Queue thread (some code that will take some time without impacting GUI rendering performance.)
    I know I could put that Event's action command into a synchronized Queue, and have a worker thread checking the queue and taking action when it finds a command there. Likewise, I could flag a volatile boolean as true, and have a worker thread check the flag and take action when true.
    Or (and I suspect this is best), I could create a new SwingWorker thread right in actionPerformed().
    Any opinions on what makes sense?

    pkwooster: Yep. That's what I meant.
    As for the design pattern, Observer was the pattern I was intending to use (and have already implemented). Would anyone argue that another method is more efficient or "correct"?
    My sample project is:
    Business Object -> Main Dialog -> Embedded Dialog
    The Main Dialog contains no business logic - just simple navigation events. The Embedded Dialog contains the real controls and reports any interaction using Swing events, which the Main Dialog picks up.
    I then set up the Observer pattern between the Main Dialog and the Business Object.

  • Unicode font for swing components

    Hi all,
    I'd like to set a Swing component (a JLabel) to a particular font so it will properly display Unicode Greek text. I've been reading all about physical vs. logical fonts, and I've read through the various Sun docs/faqs on Internationalization, Fonts, and Unicode, but I just can't get this to work. I think I'm missing something more basic here about selecting my font. My test word is the Greek "khairete," with an accent over the iota. Here is the Unicode:
    \u03c7\u03b1\u1f77\u03c1\u03b5\u03c4\u03b5
    The trick is that accented iota.
    I can launch an xterm that shows the characters I want like this:
    $ xterm -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 &
    That tells me that if I can get Java to use that font, then I'm all set. I'm trying the following test program:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    public class GUI extends JFrame {
    public static final String MESSAGE = "\u03c7\u03b1\u1f77\u03c1\u03b5\u03c4\u03b5";
    public GUI() throws Exception {
    super();
    Font[] fonts;
    Container container;
    JLabel label;
    fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (int j=0;j<fonts.length;j++) {
    System.out.println(fonts[j]);
    container = getContentPane();
    container.setLayout(new GridLayout(0, 1));
    // try with the default font
    label = new JLabel(MESSAGE);
    container.add(label);
    printFont(label.getFont());
    // see what the default font looks like when PLAIN (to compare with fonts below)
    label = new JLabel(MESSAGE);
    label.setFont(label.getFont().deriveFont(Font.PLAIN, 12));
    container.add(label);
    printFont(label.getFont());
    // this looks the same as the default font, meaning we didn't find what we asked for.
    label = new JLabel(MESSAGE);
    label.setFont(new Font("-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1", Font.PLAIN, 12));
    container.add(label);
    printFont(label.getFont());
    // this also falls back to the default.
    label = new JLabel(MESSAGE);
    label.setFont(Font.getFont("-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1"));
    container.add(label);
    printFont(label.getFont());
    // this (of course) falls back to the default.
    label = new JLabel(MESSAGE);
    label.setFont(Font.getFont("not a font name"));
    container.add(label);
    printFont(label.getFont());
    // try every font we've got!
    for (int j = 0; j < fonts.length; j++) {
    label = new JLabel(fonts[j] + ": " + MESSAGE);
    label.setFont(fonts[j].deriveFont(Font.PLAIN, 12));
    container.add(label);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    show();
    public static void printFont(Font f) {
    System.out.println(f);
    if (f != null) {
    public static void main(String[] args) throws Exception {
    GUI me = new GUI();
    But nothing in this code succeedings in printing \u1f77. As I've said, the plain old xterm can do it. I think my problem is that I haven't successfully referenced the desired font in the Java code. But how do I do this? These are the fonts available to me, according to the code above:
    java.awt.Font[family=Bitstream Charter,name=Bitstream Charter,style=plain,size=1]
    java.awt.Font[family=Bitstream Charter,name=Bitstream Charter Bold,style=plain,size=1]
    java.awt.Font[family=Bitstream Charter,name=Bitstream Charter Bold Italic,style=plain,size=1]
    java.awt.Font[family=Bitstream Charter,name=Bitstream Charter Italic,style=plain,size=1]
    java.awt.Font[family=Courier,name=Courier,style=plain,size=1]
    java.awt.Font[family=Courier 10 Pitch,name=Courier 10 Pitch,style=plain,size=1]
    java.awt.Font[family=Courier 10 Pitch,name=Courier 10 Pitch Bold,style=plain,size=1]
    java.awt.Font[family=Courier 10 Pitch,name=Courier 10 Pitch Bold Italic,style=plain,size=1]
    java.awt.Font[family=Courier 10 Pitch,name=Courier 10 Pitch Italic,style=plain,size=1]
    java.awt.Font[family=Courier,name=Courier Bold,style=plain,size=1]
    java.awt.Font[family=Courier,name=Courier Bold Italic,style=plain,size=1]
    java.awt.Font[family=Courier,name=Courier Italic,style=plain,size=1]
    java.awt.Font[family=Cursor,name=Cursor,style=plain,size=1]
    java.awt.Font[family=Lucida Bright,name=Lucida Bright Demibold,style=plain,size=1]
    java.awt.Font[family=Lucida Bright,name=Lucida Bright Demibold Italic,style=plain,size=1]
    java.awt.Font[family=Lucida Bright,name=Lucida Bright Italic,style=plain,size=1]
    java.awt.Font[family=Lucida Bright,name=Lucida Bright Regular,style=plain,size=1]
    java.awt.Font[family=Lucida Sans,name=Lucida Sans Demibold,style=plain,size=1]
    java.awt.Font[family=Lucida Sans,name=Lucida Sans Demibold Oblique,style=plain,size=1]
    java.awt.Font[family=Lucida Sans,name=Lucida Sans Oblique,style=plain,size=1]
    java.awt.Font[family=Lucida Sans,name=Lucida Sans Regular,style=plain,size=1]
    java.awt.Font[family=Lucida Sans Typewriter,name=Lucida Sans Typewriter Bold,style=plain,size=1]
    java.awt.Font[family=Lucida Sans Typewriter,name=Lucida Sans Typewriter Bold Oblique,style=plain,size=1]
    java.awt.Font[family=Lucida Sans Typewriter,name=Lucida Sans Typewriter Oblique,style=plain,size=1]
    java.awt.Font[family=Lucida Sans Typewriter,name=Lucida Sans Typewriter Regular,style=plain,size=1]
    java.awt.Font[family=Luxi Mono,name=Luxi Mono Bold,style=plain,size=1]
    java.awt.Font[family=Luxi Mono,name=Luxi Mono Bold Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Mono,name=Luxi Mono Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Mono,name=Luxi Mono Regular,style=plain,size=1]
    java.awt.Font[family=Luxi Sans,name=Luxi Sans Bold,style=plain,size=1]
    java.awt.Font[family=Luxi Sans,name=Luxi Sans Bold Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Sans,name=Luxi Sans Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Sans,name=Luxi Sans Regular,style=plain,size=1]
    java.awt.Font[family=Luxi Serif,name=Luxi Serif Bold,style=plain,size=1]
    java.awt.Font[family=Luxi Serif,name=Luxi Serif Bold Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Serif,name=Luxi Serif Oblique,style=plain,size=1]
    java.awt.Font[family=Luxi Serif,name=Luxi Serif Regular,style=plain,size=1]
    java.awt.Font[family=Utopia,name=Utopia Bold,style=plain,size=1]
    java.awt.Font[family=Utopia,name=Utopia Bold Italic,style=plain,size=1]
    java.awt.Font[family=Utopia,name=Utopia Italic,style=plain,size=1]
    java.awt.Font[family=Utopia,name=Utopia Regular,style=plain,size=1]
    java.awt.Font[family=dialog,name=dialog,style=plain,size=1]
    java.awt.Font[family=dialog,name=dialog.bold,style=plain,size=1]
    java.awt.Font[family=dialog,name=dialog.bolditalic,style=plain,size=1]
    java.awt.Font[family=dialog,name=dialog.italic,style=plain,size=1]
    java.awt.Font[family=dialoginput,name=dialoginput,style=plain,size=1]
    java.awt.Font[family=dialoginput,name=dialoginput.bold,style=plain,size=1]
    java.awt.Font[family=dialoginput,name=dialoginput.bolditalic,style=plain,size=1]
    java.awt.Font[family=dialoginput,name=dialoginput.italic,style=plain,size=1]
    java.awt.Font[family=monospaced,name=monospaced,style=plain,size=1]
    java.awt.Font[family=monospaced,name=monospaced.bold,style=plain,size=1]
    java.awt.Font[family=monospaced,name=monospaced.bolditalic,style=plain,size=1]
    java.awt.Font[family=monospaced,name=monospaced.italic,style=plain,size=1]
    java.awt.Font[family=sansserif,name=sansserif,style=plain,size=1]
    java.awt.Font[family=sansserif,name=sansserif.bold,style=plain,size=1]
    java.awt.Font[family=sansserif,name=sansserif.bolditalic,style=plain,size=1]
    java.awt.Font[family=sansserif,name=sansserif.italic,style=plain,size=1]
    java.awt.Font[family=serif,name=serif,style=plain,size=1]
    java.awt.Font[family=serif,name=serif.bold,style=plain,size=1]
    java.awt.Font[family=serif,name=serif.bolditalic,style=plain,size=1]
    java.awt.Font[family=serif,name=serif.italic,style=plain,size=1]
    javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=bold,size=12]
    java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12]
    java.awt.Font[family=dialog,name=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1,style=plain,size=12]
    javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12]
    javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12]
    Apparently, I need to use the correct "name" to specify the font. So my next try was this:
    $ xlsfonts -ll -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
    name: -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
    direction: left to right
    indexing: matrix
    rows: 0x00 thru 0x30 (0 thru 48)
    columns: 0x00 thru 0xff (0 thru 255)
    all chars exist: no
    default char: 0x0000 (0)
    ascent: 14
    descent: 4
    font type: Character Cell
    bounds: width left right asc desc attr keysym
    min 9 0 0 -3 -13 0x0000
    max 9 8 9 14 4 0x0000
    properties: 23
    FONTNAME_REGISTRY
    FOUNDRY Misc
    FAMILY_NAME Fixed
    WEIGHT_NAME Medium
    SLANT R
    SETWIDTH_NAME Normal
    ADD_STYLE_NAME
    PIXEL_SIZE 18
    POINT_SIZE 120
    RESOLUTION_X 100
    RESOLUTION_Y 100
    SPACING C
    AVERAGE_WIDTH 90
    CHARSET_REGISTRY ISO10646
    CHARSET_ENCODING 1
    COPYRIGHT Public domain font. Share and enjoy.
    XMBDFEDINFO 654
    CAP_HEIGHT 10
    X_HEIGHT 7
    FONT -Misc-Fixed-Medium-R-Normal--18-120-100-100-C-90-ISO10646-1
    WEIGHT 10
    RESOLUTION 138
    QUAD_WIDTH 9
    name: -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
    direction: left to right
    indexing: matrix
    rows: 0x00 thru 0x30 (0 thru 48)
    columns: 0x00 thru 0xff (0 thru 255)
    all chars exist: no
    default char: 0x0000 (0)
    ascent: 14
    descent: 4
    font type: Character Cell
    bounds: width left right asc desc attr keysym
    min 9 0 0 -3 -13 0x0000
    max 9 8 9 14 4 0x0000
    properties: 23
    FONTNAME_REGISTRY
    FOUNDRY Misc
    FAMILY_NAME Fixed
    WEIGHT_NAME Medium
    SLANT R
    SETWIDTH_NAME Normal
    ADD_STYLE_NAME
    PIXEL_SIZE 18
    POINT_SIZE 120
    RESOLUTION_X 100
    RESOLUTION_Y 100
    SPACING C
    AVERAGE_WIDTH 90
    CHARSET_REGISTRY ISO10646
    CHARSET_ENCODING 1
    COPYRIGHT Public domain font. Share and enjoy.
    XMBDFEDINFO 654
    CAP_HEIGHT 10
    X_HEIGHT 7
    FONT -Misc-Fixed-Medium-R-Normal--18-120-100-100-C-90-ISO10646-1
    WEIGHT 10
    RESOLUTION 138
    QUAD_WIDTH 9
    (Yes, xlsfonts prints two entries.)
    Here is a bit more data:
    [pjungwir@mccurdy unicode_gui]$ uname -a
    Linux mccurdy.nfic.com 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386 GNU/Linux
    [pjungwir@mccurdy unicode_gui]$ cat /etc/redhat-release
    Red Hat Linux release 8.0 (Psyche)
    [pjungwir@mccurdy unicode_gui]$ java -version
    java version "1.4.2_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
    If anyone has any suggestions, I would really appreciate it. I'd like to find an answer that doesn't involve editing the font.properties file.
    Thanks,
    --Paul

    Hi Sojan,
    first up, forget the notion of even tinkering with the font.properties file if you can. It's an old, outdated method of setting up the fonts that Sun doesn't even support any more. Use setFont() where you can, and die trying in the process! ;-)
    One thing I would check is which font each AWT component currently thinks it has. It's easy enough to set the font system wide with Swing components, but I'm not sure if that capability extends to AWT components (I've certainly had trouble with it in various places in the past). While you've set up the Chinese font correctly, your AWT components might still be stuck with the Java default (Helvetica, or whatever it is, which is incapable of displaying Chinese), and hence displaying the rectangles because they don't know how to handle the foreign characters. You might need to set SimSun as the font for each of your AWT components individually at a worst-case scenario.
    Hope that helps,
    Martin Hughes

  • Swing component's opaque property

    Recenetly I read an article about "Painting in AWT and Swing" and feel confused about some points in the article.
    http://java.sun.com/products/jfc/tsc/articles/painting/index.html
    The article mentioned several Swing Painting Guidelines, I have question about the following two paragraphs:
    6. If a Swing component's opaque property is set to true, then it is agreeing to paint all of the bits contained within its bounds (this includes clearing it's own background within paintComponent()), otherwise screen garbage may result.
    7. Setting either the opaque or optimizedDrawingEnabled properties to false on a component will cause more processing on each paint operation, therefore we recommend judicious use of both transparency and overlapping components.
    For the No.7, it's said setting the opaque to false will cause more process on each paint operation, I think it should changed to ture, since if set opaque property to true, it will paint all the bits contained within bounds as described in No.6.
    So is this an error? What on earth is efficient for the opaque property value?
    Thanks!

    For the No.7, it's said setting the opaque to false will cause more process on each paint operationWhen you create an application you do something like this:
    create a frame
    add a panel to the frame
    add a component to the panel. (lets say a JButton)
    When you click on a button you need to change the state of the button to look 'pressed'. So you need to repaint area on the screen where the button is painted.
    If the button is opaque(true) then you simply paint the button in its new state because the button is responsible for painting its background and any custom painting.
    if the button is opaque(false) then you don't paint the background which means you need to search for the parent of the button (in our example the panel). Once you find the parent you need to paint that area of the panel that the button overlays and then you do the custom painting of the button.
    So either way you have to repaint the same area. Hopefully it makes sense that painting a single component would be more efficient than painting parts of two separate components and determining which two components to repaint and what area to repaint of each component.

Maybe you are looking for

  • No longer connects to the wireless

    My aunty them have a router set up to their desktop and my cousin's laptop connects perfectly fine to it. Mines used to set up just as perfect until a few days ago. Now when I try to connect, it just says "connection timed out."

  • Can I use a 2 TB Ext HD?

    The Question: Using my older Dell desktop*, can I safely buy a 2 TB ext HD and (with no problems) connect using USB ?  *(Dimension 8254, with Pentium 4 CPU 2.8 GHz and 2 GB RAM, running Win XP Pro 2002 version and Service Pack 3.  The int HD is Maxto

  • Suggestion for Airport Extreme

    Apple, Please, please, please, add an audio jack to the Airport Extreme that works with Airplay. I suspect my setup is like many others where my cable modem, phone, and airport express are located in the living room by the main entertainment center.

  • Updating to iOS 7 broke my Wi-Fi (and how I fixed it)

    I have an iPad 2; it worked fine; I updated from iOS 6 to iOS 7. Immediately after updating, it could not connect to my home WiFi network (Airport Extreme). All other devices on the network (MacBook, iPhone, iPod, Roku, Wii, wireless printers) contin

  • Service process is running in code page [MS Windows Latin 1 (ANSI), superse

    All, I am trying to create Integration service, getting errors on Windows. Can anyone tell me where exactly where the service process is pulling the Latin 1(Ansi) settings from. I am stuck on this setup. regards girish