Create superscript in a Jlabel and a JTextField

Hi,
I can't seem to figure out how to create superscript.
I want to display co2 with the 2 superscript as in scientific notation.
I think I need something like:
import java.awt.font.*;     // for formatting superscript etc.
and something like:
// setSuperscript( MutableAttributeSet a, boolean b);
setSuperscriptString e, 2, true);
  String e = "2";
  output = new JTextField("CO" + e ); .
Anyone have an example?
thanks!
-- HSC --

can't open that link, do you mean:
http://forum.java.sun.com/thread.jsp?forum=54&thread=375413&tstart=120&trange=15
about the unicode symbols? Saw it but wanted to know about the MutableAttributeSet stuff I posted. It seems like there's a way to reformat fonts with that, I just don't understand it's implementation. I don't know where else to get info about these classes & methods in the API's. Be nice to see a clear description or an example of usage.
BTW, hows BC this time of year?

Similar Messages

  • Creating a gridlayout of jlabels and jbuttons in a JPanel

    The assignment:
    "Create a JPanel that contains an 8x8 checkerboard. Make all of the red squares JButtons and be sure to add them to the JPanel. Make all of the black squares JLabels and add them to the JPanel. Don't forget, you must use the add method to attach the JPanel to the JApplet's contentPane but that there is no contentPane for a JPanel. Be sure to set up any interfaces to handle the JButtons. Use a GridLayout to position and size each of the components instead of absolute locations and sizes."
    This assignment introduces the JPanel to me for the first time, I have not seen what the JDialog and JFrame are.
    What I have:
    import java.awt.*;
    import javax.swing.*;
    * Class CheckerBoard - write a description of the class here
    * @author (your name)
    * @version (a version number)
    public class CheckerBoard extends JPanel
        JButton redSquare;
        JLabel blackSquare;
         * Called by the browser or applet viewer to inform this JApplet that it
         * has been loaded into the system. It is always called before the first
         * time that the start method is called.
        public void init()
            JPanel p = new JPanel();
            setLayout(new GridLayout(8,8));
            setSize(512,512);
            ImageIcon red = new ImageIcon("GUI-006-RedButton.png");
            ImageIcon black = new ImageIcon("GUI-006-BlackSquare.png");
            blackSquare = new JLabel(black);
            blackSquare.setSize(64,64);
            redSquare = new JButton(red);
            redSquare.setSize(64,64);
            for (int i = 0; i < 64; i++) {
                if ((i % 2) == 1)
                    add(blackSquare);
                else
                   add(redSquare);
            // this is a workaround for a security conflict with some browsers
            // including some versions of Netscape & Internet Explorer which do
            // not allow access to the AWT system event queue which JApplets do
            // on startup to check access. May not be necessary with your browser.
            JRootPane rootPane = this.getRootPane();   
            rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
    }After successfully compiling it when I try to run it there appears to be nothing to run. I've tried messing around with content panes but I'm not sure if I need to add one for this assignment at all.

    Some suggestions:
    1) First and foremost, read about JPanels, JApplets, and JFrames. None of the help you can get here will substitute for your applying yourself towards this, absolutely none, and judging by your code, you have your work cut out for you.
    2) Don't have your JPanel initialize with an init method, that's what Applets and JApplets do. Instead have it initialize with a proper constructor.
    3) I'm wondering if your "workaround" code belongs in the JApplet that contains the JPanel and not in the JPanel. It has nothing to do with the JPanel's mission. For instance, what if you later decide to place this panel into a JFrame?
    4) Avoid "setSize", and if at all possible, use "setPreferredSize" instead. You are working with LayoutManagers who do the size setting. You are best served by suggesting the size to them.
    5) Please ask specific questions. Just dumping your code without a question is considered quite rude here. We are all volunteers. If you want our free advice, you really should be considerate enough to make it easy for us to help you.
    Good luck.
    Edited by: Encephalopathic on Dec 21, 2007 6:14 PM

  • How to align JLabels and set them to the rightmost position before the JTextField?

    I don't know if this is the right group to ask in.
    I am using the miglayout,
    and I want every JLabels to locate at
    the rightmost position next to the JTextField after it
    so that there won't be any gaps between
    the JLabels and the JTextFields
    Any example to show
    Thanks
    Jack

    Mod: moved from JP.

  • How to print JTextPane containing JTextFields, JLabels and JButtons?

    Hi!
    I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
    I wrote this small programm to demonstrate my problem:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.print.PrinterException;
    public class TextPaneTest2 extends JFrame {
         private void insertStringInTextPane(String text,
                   StyledDocument doc) {
              try {
                   doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
              catch (BadLocationException x) {
                   x.printStackTrace();
         private void insertTextFieldInTextPane(String text,
                   JTextPane tp) {
              JTextField tf = new JTextField(text);
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(tf);
         private void insertButtonInTextPane(String text,
                   JTextPane tp) {
              JButton button = new JButton(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(button);
         private void insertLabelInTextPane(String text,
                   JTextPane tp) {
              JLabel label = new JLabel(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(label);
         public TextPaneTest2() {
              StyledDocument doc = new DefaultStyledDocument();
              StyledDocument printDoc = new DefaultStyledDocument();
              JTextPane tp = new JTextPane(doc);
              JTextPane printTp = new JTextPane(printDoc);
              this.insertStringInTextPane("Text ", doc);
              this.insertStringInTextPane("Text ", printDoc);
              this.insertTextFieldInTextPane("Field", tp);
              this.insertTextFieldInTextPane("Field", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertButtonInTextPane("Button", tp);
              this.insertButtonInTextPane("Button", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertLabelInTextPane("Label", tp);
              this.insertLabelInTextPane("Label", printTp);
              this.insertStringInTextPane(" Text Text", doc);
              this.insertStringInTextPane(" Text Text", printDoc);
              tp.setEditable(false);
              printTp.setEditable(false);
              this.getContentPane().add(tp);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible(true);
              JOptionPane.showMessageDialog(tp, "Start printing");
              try {
                   tp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
              try {
                   printTp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new TextPaneTest2();
    }First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
    Thanks!

    I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.

  • Help with JLabels and JTextFields

    I'm experimenting with JLabels and JTextFields in a basic JFrame. What I am trying to accomplish (without success) is to align a JLabel above and centered on a JTextField. The tutorials are confusing me. Any help would be greatly appreciated. a Sample of code is ...
    JLabel  myTextLabel = new JLabel("Who's text Field?");
    JTextField myTextField = new JTextField("My Text Field");...after reading the tutorial I thought that I needed to assign L&F variables to the JLabel ... i.e.
    JLabel myTextLabel = new JLabel("Who's text field?:", JLabel.CENTER, JLabel.TOP); but this results in an error when compiling. (cannot find symbol), so I thought I need to assign the JLabel to the JTextField. i.e.
    myTextLabel.setLabelFor(myTextField);Then I get "identifier" expected. So now being completely confused I am here asking "How do I?" :)
    Thanks in advance!

    Most likely, you need to think a little more about using a layout manager to hlp you along the way. If memory serves, the default layout manager for a JPanel is FlowLayout and that will simply place the components you add to the panel one after another and allow each to adopt it's preferred size.
    One way to ensure that the two compoenets were sized equally, would be to use the GridLayout layout manager and create either one row with two columns, or two rows with one column on each. Then add the compoennets to each of the 'cells' so to speak and that should ensure that they are both the same size.
    As to making the text centered in each, both the JLabel and JtextField classes have amethod called setHorizontalAlignment(); it can be used to aligh the text as you require.
    Simply create an instance of the class;
    JLabel aLabel = new JLabel("Some Text");
    // Then set the alignment
    aLabel.setHorizontalAlignment(SwingConstants.CENTER);Or, do the whole operation i one step
    JLabel aLabel = new JLabel("Sone Text", SwingConstants.CENTER);and then add the componenet to the panel once you have set the layout manager.
    Remember that the label.textfield will have to be wide enought to make it obvious that the text is centered!

  • Layout of JLabels and JTextFields

    Hi!
    I am looking for an easy way to layout JLabels and JTextFields side by side like this:
    jlabel             jtextField
    small jlabel       jtextField
    longer jlabel      jtextFieldAny ideas on how to do this?
    Peter

    Read this section from the Swing tutorial on "Using Layout Managers":
    http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html
    The easiest way is to use a GridLayout.
    JPanel panel = new JPanel();
    panel.setLayout( new GridLayout(0, 2) );
    panel.add( new JLabel("...") );
    panel.add( new JTextField(10) );
    panel.add( new JLabel("...") );
    panel.add( new JTextField(10) );
    A more complicated, but more flexible way is to use a GridBagLayout. Something like this:
    public class ActivityPanel extends JPanel
         public ActivityPanel()
              setBorder( new EmptyBorder(5, 5, 5, 5) );
              setLayout( new GridBagLayout() );
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.insets = new Insets(5, 10, 5, 10);
              // add street
              JLabel lStreet = new JLabel("Street");
              JTextField cStreet = new JTextField(32);
              addRow(gbc, lStreet, cStreet);
              // add city
              JLabel lCity = new JLabel("City");
              JTextField cCity = new JTextField(32);
              addRow(gbc, lCity, cCity);
         private void addRow(GridBagConstraints gbc, Component left, Component right)
              gbc.gridx = GridBagConstraints.RELATIVE;
              gbc.gridy = GridBagConstraints.RELATIVE;
              gbc.gridheight = 1;
              gbc.gridwidth = 1;
              gbc.anchor = GridBagConstraints.EAST;
              add(left, gbc);
              gbc.gridwidth = GridBagConstraints.REMAINDER;
              gbc.anchor = GridBagConstraints.WEST;
              add(right, gbc);
    }

  • Align JLabels and JTextFields vertically in different areas

    I like to have 3 TitledBorders for 3 different areas of my frame.
    Each area has its own components - JLabels, JTextField, etc.
    How to align JLabels and JTextFields vertically in different areas?
    e.g. for the following test program, how to configure label1, label2, label3 so that their right sides all align vertically and
    tf1, tf2, tf3 so that their left sides all align vertically?
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.border.TitledBorder;
    public class TitledBorderDemo extends JFrame {
      public TitledBorderDemo() {
        super("TitledBorderDemo");
        JTextField tf1 = new JTextField("hello", 6);
        JTextField tf2 = new JTextField("hello", 12);
        JTextField tf3 = new JTextField("test");
        JTextField tf4 = new JTextField("test2");
        JLabel label1 = new JLabel("1234567890ertyuiyup label");
        JLabel label2 = new JLabel("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz long label");
        JLabel label3 = new JLabel("short label");
        JLabel label4 = new JLabel("test");
        JPanel panel_tf = new JPanel(new GridBagLayout());
        JPanel panel_pf = new JPanel(new GridBagLayout());
        JPanel panel_ftf = new JPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints(0, 0, 3, 3,
                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(10, 10, 10, 10), 0, 0);
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_tf.add(label1, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_tf.add(tf1, constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_pf.add(label2, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_pf.add(tf2, constraints);
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.gridwidth = 2;
        constraints.anchor = GridBagConstraints.WEST;
        panel_ftf.add(label3, constraints);
        constraints.gridx = 2;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        panel_ftf.add(tf3, constraints);
        constraints.gridx = 3;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.WEST;
        panel_ftf.add(label4, constraints);
        constraints.gridx = 4;
        constraints.anchor = GridBagConstraints.EAST;
        panel_ftf.add(tf4, constraints);
        panel_tf.setBorder(new TitledBorder("JTextField1"));
        panel_pf.setBorder(new TitledBorder("JTextField2"));
        panel_ftf.setBorder(new TitledBorder("JTextField3"));
        JPanel pan = new JPanel(new GridLayout(3, 1, 10, 10));
        pan.add(panel_tf);
        pan.add(panel_pf);
        pan.add(panel_ftf);
        this.add(pan);
      public static void main(String args[]) {
        JFrame frame = new TitledBorderDemo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 450);
        frame.setVisible(true);
    }

    Thank you! It works!
    I add some labels & components to your demo program.
    Most of the components align vertically.
    How to align the "Country", "Test2" & "Extension" labels on the right sides?
    How to align their corresponding components so that their left sides all align vertically?
    How to make the Cancel button stick to the Save button
    (i.e. eliminate the gap between the Cancel and the Save button)?
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class TitledBorderDemoNew extends JFrame {
      public TitledBorderDemoNew() {
        super("TitledBorderDemoNew");
        JLabel nameLabel = new JLabel("Name");
        JTextField nameText = new JTextField(20);
        JLabel addressLabel = new JLabel("Address (City & State)");
        JTextField addressText = new JTextField(40);
        JLabel countryLabel = new JLabel("Country");
        JTextField countryText = new JTextField(30);
        JLabel testLabel = new JLabel("Test");
        JTextField testText = new JTextField(20);   
        JLabel test2Label = new JLabel("Test2");
        JTextField test2Text = new JTextField(20);   
        JLabel phoneLabel = new JLabel("Phone");
        JTextField phoneText = new JTextField(20);
        JLabel extensionLabel = new JLabel("Extension");
        JTextField extensionText = new JTextField(5);
        JLabel postalCodeLabel = new JLabel("Postal Code");
        JTextField postalCodeText = new JTextField(6);
        JButton saveButton = new JButton("Save");
        JButton cancelButton = new JButton("Cancel");
        JButton commentButton = new JButton("Comment");
        int longWidth = addressLabel.getPreferredSize().width;
        GridBagConstraints constraints = new GridBagConstraints();
        JPanel p1 = new JPanel(new GridBagLayout());
        p1.setBorder(createBorder("Name"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p1.add(nameLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p1.add(nameText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p1.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p1.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p2 = new JPanel(new GridBagLayout());
        p2.setBorder(createBorder("Address"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(addressLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p2.add(addressText, constraints);
        // extra label & component
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,36,4,6);
        p2.add(countryLabel, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(countryText, constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(testLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p2.add(testText, constraints);
        // extra label & component
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,36,4,6);
        p2.add(test2Label, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p2.add(test2Text, constraints);
        constraints.gridx = 4;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p2.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p2.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p3 = new JPanel(new GridBagLayout());
        p3.setBorder(createBorder("Phone"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p3.add(phoneLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p3.add(phoneText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p3.add(extensionLabel, constraints);
        constraints.gridx = 3;
        constraints.anchor = GridBagConstraints.WEST;
        p3.add(extensionText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p3.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p3.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p4 = new JPanel(new GridBagLayout());
        p4.setBorder(createBorder("Postal Code"));
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.EAST;
        constraints.insets = new Insets(4,6,4,6);
        p4.add(postalCodeLabel, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        p4.add(postalCodeText, constraints);
        constraints.gridx = 2;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p4.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 0.0;
        p4.add(Box.createHorizontalStrut(longWidth), constraints);
        JPanel p5 = new JPanel(new GridBagLayout());
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.insets = new Insets(4,6,4,6);
        p5.add(commentButton, constraints);
        constraints.gridx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        p5.add(Box.createHorizontalGlue(), constraints);
        constraints.gridx = 2;
        constraints.gridwidth = GridBagConstraints.RELATIVE;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.EAST;
        p5.add(cancelButton, constraints);
        constraints.gridx = 3;
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.EAST;
        p5.add(saveButton, constraints);
        JPanel panel = new JPanel(new GridBagLayout());
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.weightx = 1.0;
        panel.add(p1, constraints);
        constraints.gridy = 1;
        panel.add(p2, constraints);
        constraints.gridy = 2;
        panel.add(p3, constraints);
        constraints.gridy = 3;
        panel.add(p4, constraints);
        constraints.gridy = 4;
        panel.add(p5, constraints);
        this.add(new JScrollPane(panel));
      private Border createBorder(String title)
        TitledBorder b = new TitledBorder(title);
        b.setTitleColor(Color.RED.darker());
        return b;
      public static void main(String args[]) {
        JFrame frame = new TitledBorderDemoNew();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }Edited by: 833768 on 26-Apr-2011 10:32 AM

  • How do you create superscripts subscripts in LabVIEW?

    I want to create superscripts subscripts in LabVIEW, but those are not options in the Applications Font Dialog Box. How do I do this?

    Hi,
    If you need users to create those formulas, it can get very complex. You
    cannot have font differences (or different fonts) in one string control.
    Even if you make a font with sub and superscript included, this is no
    solution.
    If you need a static formula on the front panel, make it by using several
    text boxes. For Asubscript(2)=Asubscript(1)Xsuperscript(2), one text is A =
    A X B. The other text is smaller, and has 2 1 in it. The last has a 2
    in it. When placed in the right position, it will make a fine formula.
    If the formula must be user editable, or changeble from the program, ActiveX
    is a solution. Microsoft Rich Text Box comes to mind. However, you must make
    the interface to make the selected text sub or superscript yourself. (Or
    control i
    t from the program.) A webbrowser control in combination with
    MathML also seems logical. Both solutions are not for the faint or heart...
    Regards,
    Wiebe.
    "Jim Kane" wrote in message
    news:[email protected]..
    > I want to create superscripts subscripts in LabVIEW, but those are not
    > options in the Applications Font Dialog Box. How do I do this?

  • Having probelm with JLabel and setText

    I posted a message in Java Programming but I think it will be more appropriate here. I am trying to create a calculator so I want my JLabel(output) to display the number of the button that is clicked on. I used output.setText("7") but I get an error when compiling saying <identifier> expected. Any advice would be great. Also, is there a getText method in JLabel? I need to concatenate the current contents of JLabel and the value of the button pushed. For example:
    output.setText( output.getText() + "7" );
    Anyways, here is my code. I tried to make it indent so it is easier to read but it doesn't show up once I post it.
    Thanks for you help.
    * Write a description of class calculator here.
    * @author (Jeremy Kruer)
    * @version (11/19/02)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class calculator extends JFrame
    private JButton one, two, three, four, five, six, seven, eight, nine, zero, dec, eq, plus, minus, mult, div;
    private JLabel output;
    private Container container;
    //set up GUI
    public calculator()
    //Create Title
    super("Calculator");
    //Set size and make visible
    setSize( 400, 400 );
    setVisible( true );
    container = getContentPane();
    container.setLayout( new FlowLayout() );
    //set up output
    output = new JLabel();
    container.add( output );
    //set up seven and register its event handler
    seven = new JButton( " 7 " );
    seven.addActionListener(
    //anonymouse inner class
    new ActionListener()
    //add a seven to the output diplay when clicked
    output.setText( "7" );
    }//end anonymouse inner class
    ); //end call to addActionListener
    container.add( seven );
    //set up eight
    eight = new JButton( " 8 " );
    container.add( eight );
    //set up nine
    nine = new JButton( " 9 " );
    container.add( nine );
    //set up div
    div = new JButton( " / " );
    container.add( div );
    //set up four
    four = new JButton( " 4 " );
    container.add( four );
    //set up five
    five = new JButton( " 5 " );
    container.add( five );
    //set up six
    six = new JButton( " 6 " );
    container.add( six );
    //set up mult
    mult = new JButton( " * " );
    container.add( mult );
    //set up one
    one = new JButton( " 1 " );
    container.add( one );
    //set up two
    two = new JButton( " 2 " );
    container.add( two );
    //set up three
    three = new JButton( " 3 " );
    container.add( three );
    //set up minus
    minus = new JButton( " - " );
    container.add( minus );
    //set up zero
    zero = new JButton( " 0 " );
    container.add( zero );
    //set up dec
    dec = new JButton( " . " );
    container.add( dec );
    //set up eq
    eq = new JButton( " = " );
    container.add( eq );
    //set up plus
    plus = new JButton( " +" );
    container.add( plus );
    //Set size and make visible
    setSize( 220, 250 );
    setVisible( true );
    //execute application
    public static void main( String args[] )
    calculator application = new calculator();
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    // not tested but try it ...
    1. put an empty string into the JLabel
    declare
    String labString = "";
    (and declare the JLabel too)
    2. initialise label - init() {
    myLabel = new JLabel(labString)
    3. activate
    actionPerformed(ActionEvent evt) {
    if (evt.getSource()==button#7) {
    labString = getActionCommand();
    myLabel.setText(labString);
    validate();
    Something like that anyway - it should work + if you 'play' with it, you can probably make it a bit more efficiently than the methods I've outlined here.

  • JLabel and JButton

    I got my clock hands issue figured out, now I am trying to get a JButton and JLabels and JTextboxes in. I think I have the code for the labels right, but nothing shows up....any suggestions or places for me to look for help?
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class clocky extends Frame {
         public static void main(String args[])
                   Frame frame = new clocky();
                   frame.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent we){
                             System.exit(0);
                   frame.setSize(300, 300);
                   frame.setVisible(true);
         private void createButton()
              JButton button = new JButton("Show Time");
         private void labels()
         JLabel hourLabel = new JLabel("Hour: ", JLabel.LEFT);
         hourLabel.setVerticalAlignment(JLabel.TOP);
         JLabel minLabel = new JLabel("Minute: ", JLabel.LEFT);
         minLabel.setVerticalAlignment(JLabel.TOP);
         final int centerX = 150;
         final int centerY = 180;
         Shape circle = new Ellipse2D.Double(50, 80, 200, 200);
         public void paint(Graphics g)
              Graphics2D ga = (Graphics2D)g;
              ga.draw(circle);
              //mins hand 6
              //ga.drawLine(150, 90, centerX, centerY); //00     +90 -90
              ga.drawLine(240, 180, centerX, centerY); //15      +90 +90
              //ga.drawLine(150, 270, centerX, centerY); //30      -90 +90
              //ga.drawLine(60, 180, centerX, centerY); //45      -90 -90
         //hrs hand 2.66666666
              ga.drawLine(150, 140, centerX, centerY); //00          +40 -40
              //ga.drawLine(190, 180, centerX, centerY); //15           +40 +40
              //ga.drawLine(150, 220, centerX, centerY); //30           -40 +40
              //ga.drawLine(110, 180, centerX, centerY); //45           -40 -40
    }

    >
    I got my clock hands issue figured out, now I am trying to get a JButton and JLabels and JTextboxes in. I think I have the code for the labels right, >You have methods to create buttons and labels, but nothing calls those methods, and even if hey were called, the created components are added to no container, and are lost at the end of the method.
    >
    ..but nothing shows up....>Wrong, the clock face painted directly to the JFrame shows. And that brings me to the second point. If you added those components to a frame that overrides paint, they will disappear. Once you override paint, it is up to you to paint everything that needs painting.
    This is why I would rethink your entire strategy. Override paintComponent(Graphics) in a ClockFace that extends JPanel. ClockFace should also set or override the preferred size. Then add the ClockFace object to another JPanel(s) (e.g. mainPanel) containing the JButton(s), JLabel(s) and ClockFace. Finally, add an EmptyBorder around mainPanel, and set it as the content pane of the JFrame.
    And please remember to use the 'code' tags to keep code formatted. To achieve that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.

  • Load a redrawn image into a JLabel and save it into a BufferedImage?

    Hello, I'm doing a small application to rotate an image, it works, but I'd like to show it into a JLabel that I added, and also store the converted image into a BufferedImage to save it into a database, this is what I have so far:
    public void getImage() {
    try{
    db_connection connect = new db_connection();
    Connection conn = connect.getConnection();
    Statement stmt = conn.createStatement();
    sql = "SELECT image " +
    "FROM image_upload " +
    "WHERE image_id = 1";
    rset = stmt.executeQuery(sql);
    if(rset.next()){
    img1 = rset.getBinaryStream(1);
    buffImage = ImageIO.read(img1);
    rset.close();
    } catch(Exception e){
    System.out.println(e);
    public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    ImageIcon imgIcon = new ImageIcon(buffImage);
    AffineTransform tx = AffineTransform.getRotateInstance(rotacion, imgIcon.getIconWidth()/2, imgIcon.getIconHeight()/2);
    g2.drawImage(imgIcon.getImage(), tx, this);
    jLabel1.setIcon(imgIcon);
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    setRotacion(getRotacion() + 1.5707963249999999);
    repaint();
    I get the image from a db, then using the paint() method I rotate the image, it works, but the new image is outside of the JLabel and I don't know how to assign the new one into the JLabel (like overwritting the original) and also how to store the new image into a BufferedImage to upload it into the database converted, thanks in advanced, any help would be appreciated, thanks!!
    Edited by: saman0suke on 25-dic-2011 14:07
    Edited by: saman0suke on 25-dic-2011 15:08

    I was able already to fill the JLabel with the modified content, just by creating a new BufferedImage, then create this one into a Graphics2D object and the drawing the image into it, last part, inserting the modified image into the database, so far, so good, thanks!
    EDIT: Ok, basic functionality is ok, I can rotate the image using AffineTransform class, and I can save it to the database and being displayed into a JLabel, now, there's a problem, the image for this example is 200 width and 184 height, but when I rotate it the width can be 184 and the height 200 depending on the position, but the BufferedImage that I create always read from original saved image:
    bimage = new BufferedImage(buffImage.getWidth(), buffImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Is there a way that I can tell BufferedImage new width and height after rotate it? :( as far as I understand this cannot be done because before the image bein rotated the bufferedImage is already created and, even being able to do it how can I get width and height from rotated image? thanks!
    Edited by: saman0suke on 25-dic-2011 19:40

  • Using clone() with JLabel and JButtons

    I need to find a way of making a duplicate copy of objects that extend JLabel and JButton. Do I need to implement the clone() methord manually, or is there a simpler way of doing this?

    Use a BorderLayout as the main layout. Add the two tables to the WEST and EAST.
    Create another panel using a different layout, maybe a vertical BoxLayout. Add the two buttons and then add this panel to the CENTER of the main panel.
    The secret is to nest different panels with different layout managers to achieve your desired layout.

  • Unable to see video & audio tracks as shown in "Create a sequence or timeline and add audio"

    hi,
    I'm on the https://helpx.adobe.com/creative-cloud/learn/start/premiere.html page trying to work through the Create a sequence or timeline and add audio tutorial
    And cannot see the Video & Audio, as shown in the bottom right sub-window
    I'm using a trial version of Premier pro CC downloaded yesterday. On my mac mini running 10.9.2
    does anyone know how to fix this problem?
    thanks
    david
    I am able to hear the audio.
    Message was edited by: spottedsilvertabby

    Hi,
    Error 7 is when a router or the connection to the router is broken in some way.
    Some devices have features such as Denial Of Service protection (DoS) that cut a particular Internet Port when it thinks too much data is coming (Presuming it is an attack.)
    iChat 5 in Leopard is not capped by the System Preferences > Quicktime Streaming speed (which we used to suggest was set at 1.5Mbps)
    It now sees your whole Connection speed and your Upload may be much faster than this.
    Your Download is likely to be much faster. However iChat will tend to operate at the lower figure of your Upload.
    DoS features are threshold based.
    You may now be bumping in to this Threshold where you were not before.
    SPI (Stateful packet Inspection) does a different job but has the same effect when it is overloaded by the speed of the data.
    If you have either of these features, turn them Off (Disable them)
    7:25 PM Friday; October 2, 2009

  • Creating tables on SQL studio and viewing the table in the SAP system

    i have just created a table using the SQL studio and wants to use it view it in the SAP system using the SAP logon. till now i have not found a way to create it therefore any help is much appreciated.

    Hmm... you want to see tables via SAPLogon ??
    Ok, let's assume you really want to access tables via ABAP instead.
    For that you've two options:
    1. Create the table in the ABAP dictonary (SE11) exactly like you created it in the database and activate the table.
    After that you can access the table via SE16 or any ABAP as you like.
    2. You don't create the table in the ABAP dictonary and use native SQL to access the data.
    Neither of these options is meant to be the way to do it.
    The correct way would be to design the whole table in the ABAP dictionary and create the table on the database from that.
    regards,
    Lars

  • I just finished creating a movie in IMovie and now want to burn it to a DVD and make it loop.  Since I just purchased this IMac it no longer comes with IDVD.  My question is how to burn and loop a dvd without IDVD.  Thanks for any help.

    I just finished creating a movie using IMovie and want to burn it to a DVD and loop it.  Since I just purchased this mac it looks like they no longer include IDVD.  Is there something out there to help me do this.  I am new to MAC and any help would be greatly appreciated.  Thanks

    There is free open source software called Burn that will burn DVDs. Here is a link.
    If you wish to pay for software, there are many, including TOAST TITANIUM from Roxio. Apple's retail copy of iLife 11, and Apple's Compressor.
    Of these, I would say that iDVD is known for being able to create very professional looking DVDs with intros, menus, lots of interesting templates.
    Toast is much simpler and the menus and templates are more plain.
    Compressor is a professional tool that does a lot more than make DVDs. Don't expect much in the way of menus or templates.
    Burn, I have never tried, since I have iDVD and Toast for those ocasions when I need to burn a DVD. However, since it is free, I think it is worth a try.
    Each software package is a little different, but in general, in iMovie, you can use the SHARE menu to SHARE/MOVIE in Large size. Save the movie to your desktop or someplace you can easily find it. Then drag it into the tool of your choice. You can alsouse SHARE/MEDIA BROWSER/LARGE if you have iDVD or Toast.

Maybe you are looking for