Search in sources :

Example 11 with JScrollPane

use of javax.swing.JScrollPane in project jna by java-native-access.

the class ShapedWindowDemo method main.

public static void main(String[] args) {
    try {
        System.setProperty("sun.java2d.noddraw", "true");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    final JFrame frame = new JFrame("Shaped Window Demo");
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        private void showPopup(MouseEvent e) {
            final JPopupMenu m = new JPopupMenu();
            m.add(new AbstractAction("Hide") {

                public void actionPerformed(ActionEvent e) {
                    frame.setState(JFrame.ICONIFIED);
                }

                private static final long serialVersionUID = 1L;
            });
            m.add(new AbstractAction("Close") {

                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }

                private static final long serialVersionUID = 1L;
            });
            m.pack();
            m.show(e.getComponent(), e.getX(), e.getY());
        }

        public void mousePressed(MouseEvent e) {
            offset = e.getPoint();
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        public void mouseDragged(MouseEvent e) {
            if (!SwingUtilities.isLeftMouseButton(e))
                return;
            Point where = e.getPoint();
            where.translate(-offset.x, -offset.y);
            Point loc = frame.getLocationOnScreen();
            loc.translate(where.x, where.y);
            frame.setLocation(loc.x, loc.y);
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }
    };
    frame.addMouseListener(handler);
    frame.addMouseMotionListener(handler);
    ClockFace face = new ClockFace(new Dimension(150, 150));
    frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    frame.getContentPane().add(face);
    frame.setUndecorated(true);
    try {
        Shape mask = new Area(new Ellipse2D.Float(0, 0, 150, 150));
        WindowUtils.setWindowMask(frame, mask);
        if (WindowUtils.isWindowAlphaSupported()) {
            WindowUtils.setWindowAlpha(frame, .7f);
        }
        frame.setIconImage(face.getIconImage());
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocation(100, 100);
        frame.setVisible(true);
    } catch (UnsatisfiedLinkError e) {
        e.printStackTrace();
        String msg = e.getMessage() + "\nError loading the JNA library";
        JTextArea area = new JTextArea(msg);
        area.setOpaque(false);
        area.setFont(UIManager.getFont("Label.font"));
        area.setEditable(false);
        area.setColumns(80);
        area.setRows(8);
        area.setWrapStyleWord(true);
        area.setLineWrap(true);
        JOptionPane.showMessageDialog(frame, new JScrollPane(area), "Library Load Error: " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) Shape(java.awt.Shape) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) Point(java.awt.Point) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) Ellipse2D(java.awt.geom.Ellipse2D) Area(java.awt.geom.Area) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) AbstractAction(javax.swing.AbstractAction) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 12 with JScrollPane

use of javax.swing.JScrollPane in project OpenNotebook by jaltekruse.

the class ObjectPropertiesFrame method generatePanel.

/**
	 * Generates a menu for adjusting the properties of a mathobject.
	 * 
	 * @param o - object to base menu panel on
	 */
public void generatePanel(MathObject o) {
    System.out.println("generate panel" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o == null) {
        return;
    }
    this.getContentPane().removeAll();
    object = o;
    JPanel panel = mainPanel;
    mainPanel.removeAll();
    adjusters.removeAllElements();
    listAdjusters.removeAllElements();
    this.setTitle(o.getType());
    JTabbedPane panelTabs = null;
    JPanel tabOneContents = null, tabTwoContents = null;
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.weighty = 1;
    con.insets = new Insets(2, 2, 2, 2);
    con.gridx = 0;
    con.gridy = 0;
    System.out.println("end init stuff" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o instanceof GraphObject || (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // add a tabbed pane to make it more reasonable and avoid scrolling
        panelTabs = new JTabbedPane();
        this.getContentPane().add(panelTabs);
        tabOneContents = new JPanel();
        tabOneContents.setLayout(new GridBagLayout());
        tabTwoContents = new JPanel();
        tabTwoContents.setLayout(new GridBagLayout());
        System.out.println("1 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        JScrollPane tabScrollPane = new JScrollPane(panelTabs);
        tabScrollPane.getVerticalScrollBar().setUnitIncrement(16);
        tabScrollPane.getHorizontalScrollBar().setUnitIncrement(16);
        System.out.println("2 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        tabScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        if (o instanceof GraphObject) {
            panelTabs.add("Nav", tabOneContents);
            panelTabs.add("Grid", tabTwoContents);
            panel = tabOneContents;
        } else if (o instanceof ExpressionObject) {
            panelTabs.add("Expression", tabOneContents);
            panelTabs.add("Solve", tabTwoContents);
            panel = tabOneContents;
        }
        System.out.println("3 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        this.getContentPane().add(tabScrollPane);
        System.out.println("4 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    } else {
        this.getContentPane().add(scrollPane);
    }
    System.out.println("done with tabs " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = .01;
    JPanel actionPics = new JPanel();
    actionPics.setLayout(new GridLayout(0, 4, 4, 4));
    JPanel otherActions = new JPanel();
    otherActions.setLayout(new GridLayout(0, 1, 4, 4));
    ImageIcon pic;
    JButton button;
    if (!notebookPanel.isInStudentMode()) {
        for (final String s : o.getActions()) {
            pic = getIconForAction(s);
            if (pic != null)
                createButton(s, 0, 0, 0, 0, actionPics);
            else
                createButton(s, 0, 0, 0, 0, otherActions);
        }
    }
    System.out.println("teacher actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    boolean skipAction;
    for (final String s : o.getStudentActions()) {
        skipAction = false;
        if (object instanceof GraphObject) {
            // use more intuitive
            for (String str : graphNavActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (object instanceof ExpressionObject) {
            // in a separate panel to make the list of actions smaller
            for (String str : expressionOpActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (skipAction) {
            continue;
        }
        pic = getIconForAction(s);
        if (pic != null)
            createButton(s, 0, 0, 0, 0, actionPics);
        else
            createButton(s, 0, 0, 0, 0, otherActions);
    }
    System.out.println("student actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (otherActions.getComponentCount() != 0) {
        // only add panel for actions if components have been added to it
        panel.add(otherActions, con);
        con.gridy++;
    }
    if (actionPics.getComponentCount() != 0) {
        // only add panel for action pics if components have been added to it
        panel.add(actionPics, con);
        con.gridy++;
    }
    if (object instanceof GraphObject) {
        panel.add(createGraphNavigator(), con);
        con.gridy++;
    }
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode()) {
        // there are too many attributes and actions for the expression to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = tabTwoContents;
    }
    if (object instanceof ExpressionObject) {
        panel.add(createExpressionModifier(), con);
        con.gridy++;
    }
    //Switch back to tab one if in teacher mode, to allow attribute adjusters to be on the first tab
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())
        panel = tabOneContents;
    con.fill = GridBagConstraints.HORIZONTAL;
    if (o instanceof GraphObject) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        con.anchor = GridBagConstraints.PAGE_START;
        tabTwoContents.add(panel, con);
        con.anchor = GridBagConstraints.CENTER;
    }
    con.fill = GridBagConstraints.BOTH;
    for (MathObjectAttribute mAtt : o.getAttributes()) {
        if (notebookPanel.isInStudentMode() && mAtt.isStudentEditable() || (!notebookPanel.isInStudentMode() && mAtt.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            adjusters.add(getAdjuster(mAtt, notebookPanel, panel));
            if (mAtt instanceof StringAttribute) {
                // make string panels stretch vertically
                con.weighty = 1;
                con.fill = GridBagConstraints.BOTH;
            } else {
                // make all others stretch very little vertically
                con.weighty = 0;
                con.fill = GridBagConstraints.HORIZONTAL;
            }
            panel.add(adjusters.get(adjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end att adjusters:" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = 1;
    if (o instanceof GraphObject) {
        // see above comments about tabs for some objects
        panel = tabOneContents;
    }
    for (ListAttribute list : o.getLists()) {
        if ((notebookPanel.isInStudentMode() && list.isStudentEditable()) || (!notebookPanel.isInStudentMode() && list.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            listAdjusters.add(new ListAdjuster(list, notebookPanel, panel));
            panel.add(listAdjusters.get(listAdjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end lists:" + +(new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (panel.getComponentCount() == 0) {
        panel.add(new JLabel("No actions for this object"), con);
    }
    panel.revalidate();
    this.pack();
    this.update();
    this.setSize(this.getWidth() + 30, this.getHeight());
    System.out.println("done making props frame" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) StringAttribute(doc.attributes.StringAttribute) JLabel(javax.swing.JLabel) GraphObject(doc.mathobjects.GraphObject) Date(java.util.Date) GridLayout(java.awt.GridLayout) MathObjectAttribute(doc.attributes.MathObjectAttribute) ExpressionObject(doc.mathobjects.ExpressionObject) ListAttribute(doc.attributes.ListAttribute)

Example 13 with JScrollPane

use of javax.swing.JScrollPane in project jna by java-native-access.

the class BalloonManagerDemo method main.

public static void main(String[] args) {
    try {
        System.setProperty("sun.java2d.noddraw", "true");
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }
    JFrame f = new JFrame("Balloon Test");
    final String BALLOON_TEXT = "<html><center>" + "This is some sample balloon text<br>" + "which has been formatted with html.<br>" + "Click to dismiss.</center></html>";
    final JLabel content = new JLabel(BALLOON_TEXT);
    content.setIconTextGap(10);
    content.setBorder(new EmptyBorder(0, 8, 0, 8));
    content.setSize(content.getPreferredSize());
    content.setIcon(new InfoIcon());
    JLabel label = new JLabel("Click anywhere for more information");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.addMouseListener(new MouseAdapter() {

        private MouseListener listener = new MouseAdapter() {

            public void mousePressed(MouseEvent e) {
                hidePopup(e);
            }
        };

        private Popup popup;

        private void hidePopup(MouseEvent e) {
            e.getComponent().removeMouseListener(listener);
            if (popup != null)
                popup.hide();
        }

        public void mousePressed(MouseEvent e) {
            hidePopup(e);
            popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
            popup.show();
            content.getParent().addMouseListener(listener);
        }
    });
    f.getContentPane().add(label);
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.setLocation(100, 100);
    try {
        // Force a load of JNA
        WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (UnsatisfiedLinkError e) {
        e.printStackTrace();
        String msg = e.getMessage() + "\nError loading the JNA library";
        JTextArea area = new JTextArea(msg);
        area.setOpaque(false);
        area.setFont(UIManager.getFont("Label.font"));
        area.setEditable(false);
        area.setColumns(80);
        area.setRows(8);
        area.setWrapStyleWord(true);
        area.setLineWrap(true);
        JOptionPane.showMessageDialog(null, new JScrollPane(area), "Library Load Error: " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JTextArea(javax.swing.JTextArea) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MouseListener(java.awt.event.MouseListener) JFrame(javax.swing.JFrame) Popup(javax.swing.Popup) EmptyBorder(javax.swing.border.EmptyBorder)

Example 14 with JScrollPane

use of javax.swing.JScrollPane in project java-design-patterns by iluwatar.

the class Target method setup.

private void setup() {
    setLayout(new BorderLayout());
    JPanel bot = new JPanel();
    add(jt.getTableHeader(), BorderLayout.NORTH);
    bot.setLayout(new BorderLayout());
    bot.add(del, BorderLayout.EAST);
    add(bot, BorderLayout.SOUTH);
    jsp = new JScrollPane(jt);
    jsp.setPreferredSize(new Dimension(500, 250));
    add(jsp, BorderLayout.CENTER);
    del.addActionListener(new DListener());
    JRootPane rootPane = SwingUtilities.getRootPane(del);
    rootPane.setDefaultButton(del);
    setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JRootPane(javax.swing.JRootPane) Dimension(java.awt.Dimension)

Example 15 with JScrollPane

use of javax.swing.JScrollPane in project languagetool by languagetool-org.

the class LanguageManagerDialog method show.

public void show() {
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiLanguageManagerDialog"));
    // close dialog when user presses Escape key:
    // TODO: taken from ConfigurationDialog, avoid duplication:
    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener actionListener = new ActionListener() {

        @Override
        @SuppressWarnings("unused")
        public void actionPerformed(ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    };
    JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    list = new JList<>(ruleFiles.toArray(new File[ruleFiles.size()]));
    GridBagConstraints cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.fill = GridBagConstraints.BOTH;
    cons.weightx = 2.0f;
    cons.weighty = 2.0f;
    contentPane.add(new JScrollPane(list), cons);
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.fill = GridBagConstraints.HORIZONTAL;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    addButton = new JButton(messages.getString("guiAddButton"));
    addButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 0;
    buttonPanel.add(addButton, cons);
    removeButton = new JButton(messages.getString("guiRemoveButton"));
    removeButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 1;
    buttonPanel.add(removeButton, cons);
    closeButton = new JButton(messages.getString("guiCloseButton"));
    closeButton.addActionListener(this);
    cons.gridx = 1;
    cons.gridy = 2;
    buttonPanel.add(closeButton, cons);
    cons.gridx = 1;
    cons.gridy = 0;
    cons = new GridBagConstraints();
    cons.anchor = GridBagConstraints.NORTH;
    contentPane.add(buttonPanel, cons);
    dialog.pack();
    dialog.setSize(300, 200);
    dialog.setLocationByPlatform(true);
    dialog.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane) JDialog(javax.swing.JDialog)

Aggregations

JScrollPane (javax.swing.JScrollPane)657 JPanel (javax.swing.JPanel)335 JLabel (javax.swing.JLabel)210 Dimension (java.awt.Dimension)204 BorderLayout (java.awt.BorderLayout)193 JButton (javax.swing.JButton)169 JTable (javax.swing.JTable)126 BoxLayout (javax.swing.BoxLayout)125 ActionEvent (java.awt.event.ActionEvent)112 ActionListener (java.awt.event.ActionListener)95 GridBagLayout (java.awt.GridBagLayout)94 JTextArea (javax.swing.JTextArea)94 FlowLayout (java.awt.FlowLayout)81 Insets (java.awt.Insets)70 GridBagConstraints (java.awt.GridBagConstraints)65 FormLayout (com.jgoodies.forms.layout.FormLayout)57 JTextField (javax.swing.JTextField)53 Container (java.awt.Container)51 JFrame (javax.swing.JFrame)44 Color (java.awt.Color)38