Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: The <sup> tag doesn't work properly

    AFAIK it's already been declared that Swing is in 'maintenance mode' -- that the only code changes will be for bug fixes. So JLayer is probably going to be the last new Swing class; JXDatePicker and other SwingX additions and improvements will never make it to core.

    That Oracle is pushing out the FX SDK bundled with the JDK (i.e. you can't download a current JDK that doesn't include the FX SDK) does make it look like FX will make it to core sooner rather than later.

    it'll be a major overhaul to change everything from Swing to those FX components
    Yes, but you can wrap a WebView in a JFXPanel and display it in your Swing GUI. You do have to watch out for the Application thread as well as the EDT though.

    Reference: Integrating JavaFX into Swing Applications | JavaFX 2.0 Tutorials and Documentation
    Java Code:
    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.scene.Scene;
    import javafx.scene.web.WebView;
    import javax.swing.*;
    
    public class SwingWebView {
    
      public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            new SwingWebView().makeUI();
          }
        });
      }
    
      public void makeUI() {
        final JFXPanel fxPanel = new JFXPanel();
        Platform.runLater(new Runnable() {
    
          @Override
          public void run() {
            initFX(fxPanel);
          }
        });
    
        JFrame frame = new JFrame();
        frame.add(fxPanel);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      private void initFX(JFXPanel fxPanel) {
        WebView webView = new WebView();
        webView.getEngine().loadContent("<html>a<sup>b<sup>c</sup></sup></html>");
        Scene scene = new Scene(webView);
        fxPanel.setScene(scene);
      }
    }
    db
    Last edited by DarrylBurke; 02-16-2012 at 06:23 PM. Reason: Typos, typos ...
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  2. #22
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: The <sup> tag doesn't work properly

    Here's a more detailed example that demonstrates controlling an FX Node by Swing components.
    Java Code:
    import java.awt.BorderLayout;
    import javafx.application.Platform;
    import javafx.collections.ObservableList;
    import javafx.embed.swing.JFXPanel;
    import javafx.scene.Scene;
    import javafx.scene.transform.Scale;
    import javafx.scene.transform.Transform;
    import javafx.scene.web.WebView;
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    
    public class SwingWebView {
    
      private WebView webView;
    
      public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            new SwingWebView().makeUI();
          }
        });
      }
    
      public void makeUI() {
        final JFXPanel fxPanel = new JFXPanel();
        Platform.runLater(new Runnable() {
    
          @Override
          public void run() {
            initFX(fxPanel);
          }
        });
    
        final SpinnerNumberModel model = new SpinnerNumberModel(2, 0, 10, 1);
        JSpinner spinner = new JSpinner(model);
        spinner.addChangeListener(new ChangeListener() {
    
          public void stateChanged(ChangeEvent e) {
            StringBuilder sb = new StringBuilder("<html>a</html>");
            for (int i = 0; i < (Integer) model.getValue(); i++) {
              sb.insert(7 + 6 * i, "<sup>" + (char) ('b' + i) + "</sup>");
            }
            final String content = sb.toString();
            Platform.runLater(new Runnable() {
    
              @Override
              public void run() {
                webView.getEngine().loadContent(content);
              }
            });
          }
        });
        JPanel southPanel = new JPanel();
        southPanel.add(new JLabel("Superscript levels: "));
        southPanel.add(spinner);
    
        final JSlider slider = new JSlider(JSlider.VERTICAL, 1, 10, 1);
        slider.setMajorTickSpacing(1);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        slider.setSnapToTicks(true);
        slider.addChangeListener(new ChangeListener() {
    
          public void stateChanged(ChangeEvent e) {
            if ((!slider.getValueIsAdjusting())) {
    
              final int factor = slider.getValue();
              Platform.runLater(new Runnable() {
    
                public void run() {
                  ObservableList<Transform> transforms = webView.getTransforms();
                  transforms.clear();
                  transforms.add(new Scale(factor, factor, 0, 0));
                }
              });
            }
          }
        });
        JPanel eastPanel = new JPanel();
        eastPanel.setLayout(new BoxLayout(eastPanel, BoxLayout.Y_AXIS));
        eastPanel.add(new JLabel("Zoom"));
        eastPanel.add(slider);
    
        JFrame frame = new JFrame();
        frame.add(fxPanel, BorderLayout.CENTER);
        frame.add(southPanel, BorderLayout.SOUTH);
        frame.add(eastPanel, BorderLayout.EAST);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      private void initFX(JFXPanel fxPanel) {
        webView = new WebView();
        webView.getEngine().loadContent("<html>a<sup>b<sup>c</sup></sup></html>");
        Scene scene = new Scene(webView);
        fxPanel.setScene(scene);
      }
    }
    As far as FX spelling the doom of Swing, I wouldn't worry overmuch about that. People are still writing and, alas, teaching, code that uses AWT components. I don't see NetBeans being redeveloped in FX any time in the foreseeable future, and it'll take a few years before a new IDE that uses FX may appear.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #23
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,233
    Blog Entries
    7
    Rep Power
    24

    Default Re: The <sup> tag doesn't work properly

    Isn't the 'bridge' between FX and Swing quite thin? afaik, the only FX component that bridges the gap is that JFXPanel. I skimmed a bit further through the FX API documentation and FX has all counterparts of all Swing components; it even has those silly XBuilders for components X (I don't know why those things exist).

    kind regards,

    Jos

    ps. but I like it so far ;-)
    The only person who got everything done by Friday was Robinson Crusoe.

  4. #24
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: The <sup> tag doesn't work properly

    the only FX component that bridges the gap is that JFXPanel.
    That's correct. But then, JavaFX wasn't designed with Swing interoperability as a priority.

    Some earlier experiments showed that when you use both Swing and FX i.e. both the EDT and the Application threads running their event loops, the application doesn't exit without a System#exit(...) (which may come from JFrame.EXIT_ON_CLOSE).

    FX has all counterparts of all Swing components
    No color chooser (yet!) not that that's a very important component. (I'm still unable to understand how/why core Swing is still sans a date chooser.) No JOptionPane, with its convenient static methods, and no spinner.

    it even has those silly XBuilders for components X (I don't know why those things exist).
    Their methods act on the component being built and return "this" -- thus facilitating chaining method calls, much like StringBuilder/Buffer#append(...). Much the same can be done in a more readable fashion by double brace initialization. (I wish Java had a "with" keyword.)

    ps. but I like it so far ;-)
    As I see it, the real power of FX lies in its frivolous side: Effects.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #25
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: The <sup> tag doesn't work properly

    The &lt;sup&gt; tag doesn't work properly-slide_15_full_size.gif
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #26
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,233
    Blog Entries
    7
    Rep Power
    24

    Default Re: The <sup> tag doesn't work properly

    So in the second half of this year I most definitely have to upgrade to Java 7 and I have about six months to study JavaFX (are they planning to implement the last missing components? (e.g. spinners)).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  7. #27
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,988
    Rep Power
    21

    Default Re: The <sup> tag doesn't work properly

    They can't add new API to FX 2.0, so we'll have to wait for 3.0 in mid '13 and hope for a spinner.

    One of the most interesting advances in visual component design is the FX split pane, which is not limited to two children :)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Help, I can't make the JButton to work properly
    By furieux in forum New To Java
    Replies: 11
    Last Post: 01-07-2012, 06:13 PM
  2. actions dont work properly, calculator
    By lordjb in forum New To Java
    Replies: 14
    Last Post: 02-03-2011, 08:00 AM
  3. class that wont work out properly.
    By vampire-elf in forum New To Java
    Replies: 7
    Last Post: 09-07-2010, 01:39 AM
  4. Replies: 3
    Last Post: 05-06-2009, 12:11 AM
  5. Eclipse Documentation does not work properly.
    By krawetko in forum Eclipse
    Replies: 0
    Last Post: 10-05-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •