Java Code Examples for javax.swing.JPanel#setCursor()

The following examples show how to use javax.swing.JPanel#setCursor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnouncementWindow.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
	 * Constructor .
	 * 
	 * @param desktop
	 *            the main desktop pane.
	 */
	public AnnouncementWindow(MainDesktopPane desktop) {

		// Use JDialog constructor
		super("", false, false, false, false); //$NON-NLS-1$

		this.desktop = desktop;
		// Create the main panel
		JPanel mainPane = new JPanel();
		mainPane.setLayout(new BorderLayout());
//		mainPane.setBorder(new EmptyBorder(0, 0, 0, 0));
		setContentPane(mainPane);

		mainPane.setSize(new Dimension(200, 80));
		announcementLabel = new JLabel(" "); //$NON-NLS-1$
		announcementLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		announcementLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

		mainPane.add(announcementLabel, BorderLayout.CENTER);
		mainPane.setCursor(new Cursor(java.awt.Cursor.WAIT_CURSOR));

	}
 
Example 2
Source File: CursorOverlappedPanelsTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 3
Source File: CursorOverlappedPanelsTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 4
Source File: CursorOverlappedPanelsTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 5
Source File: CursorOverlappedPanelsTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 6
Source File: CursorOverlappedPanelsTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 7
Source File: CursorOverlappedPanelsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 8
Source File: CursorOverlappedPanelsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 9
Source File: CursorOverlappedPanelsTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 10
Source File: CursorOverlappedPanelsTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 11
Source File: CursorOverlappedPanelsTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 12
Source File: CursorOverlappedPanelsTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 13
Source File: CursorOverlappedPanelsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 14
Source File: CursorOverlappedPanelsTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static JPanel createPanel(Point location, boolean enabled) {
    final JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.setEnabled(enabled);
    panel.setSize(new Dimension(200, 200));
    panel.setLocation(location);
    panel.setBorder(BorderFactory.createTitledBorder(
            enabled ? "Enabled" : "Disabled"));
    panel.setCursor(Cursor.getPredefinedCursor(
            enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
    return panel;
}
 
Example 15
Source File: BinaryPanel.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public BinaryPanel(final MainPanel mainPanel) {
    super(new BorderLayout());
    this.mainPanel = mainPanel;

    add(new JScrollPane(hexEditor), BorderLayout.CENTER);

    JPanel bottomPanel = new JPanel(new BorderLayout());
    JPanel buttonsPanel = new JPanel(new FlowLayout());
    bottomPanel.add(buttonsPanel, BorderLayout.EAST);
    add(bottomPanel, BorderLayout.SOUTH);

    // todo: honfika: dynamically resize the hex data
    /*addComponentListener(new ComponentAdapter() {

     @Override
     public void componentResized(ComponentEvent e) {
     setBinaryData(binaryDataTag);
     }
     });*/
    swfInsidePanel = new JPanel();
    swfInsidePanel.setBackground(new Color(253, 205, 137));
    swfInsidePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    swfInsidePanel.add(new JLabel(AppStrings.translate("binarydata.swfInside")));
    swfInsidePanel.setFocusable(true);
    swfInsidePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    swfInsidePanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            mainPanel.loadFromBinaryTag(binaryDataTag);
            swfInsidePanel.setVisible(false);
        }

    });
    add(swfInsidePanel, BorderLayout.NORTH);
    swfInsidePanel.setVisible(false);
}
 
Example 16
Source File: ConnectionTagEditPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Adds a tag UI element for the given String
 *
 * @param tag
 * 		the tag to create
 * @param pos
 * 		the position at which to insert the tag, or -1 to append the component to the end
 */
private void addTag(String tag, int pos) {
	JLabel tagLabel = new JLabel(tag);
	tagLabel.setFont(OPEN_SANS_13);
	tagLabel.setForeground(isEnabled ? TAG_FOREGROUND : TAG_FOREGROUND_DISABLED);
	// Add border for more space
	Border border = BorderFactory.createEmptyBorder(2, editable ? 3 : 10, 3, 11);

	JPanel roundBackground = new JPanel(new BorderLayout()) {
		@Override
		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			Graphics2D g2 = (Graphics2D) g;
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setPaint(isEnabled ? TAG_BACKGROUND : TAG_BACKGROUND_DISABLED);
			// Prevent it from being cut off
			g2.fill(new RoundRectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1, 6, 6));
		}
	};

	tagLabel.setBorder(border);
	roundBackground.add(tagLabel, BorderLayout.CENTER);
	JButton removeTag = new JButton(CLOSE_SYMBOL);

	if (editable) {
		roundBackground.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
		roundBackground.setBackground(getBackground());
		removeTag.setFont(CLOSE_FONT.deriveFont(1f * removeTag.getFont().getSize()));
		removeTag.setContentAreaFilled(false);
		removeTag.setBorderPainted(false);
		removeTag.setBorder(BorderFactory.createLineBorder(getBackground()));
		roundBackground.add(removeTag, BorderLayout.WEST);
		tagToValue.put(roundBackground, tag);
		removeTag.addActionListener(e -> SwingTools.invokeLater(() -> {
			tagToValue.remove(roundBackground);
			remove(roundBackground);
			setTags.accept(new ArrayList<>(tagToValue.values()));
			revalidate();
			repaint();
		}));
		add(roundBackground, pos);
	} else {
		JPanel spacer = new JPanel(new BorderLayout());
		spacer.setBackground(getBackground());
		spacer.add(roundBackground, BorderLayout.CENTER);
		// Don't use FlowLayout gaps in view mode since they are also added to the top and left side
		spacer.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));
		add(spacer, pos);
	}

}