JSpinner not reacting on MouseWheelEvent on Windows - java

This is getting me quite confused:
I have a small application that uses a JSpinner for numeric values. I added a MouseAdapter to it, setting the value depending on the resulting event's getScrollAmount() and getWheelRotation().
Everything is working quite fine as long as the application is run on linux (Debian Wheezy, Oracle JDK 1.6.0_32). That is, scrolling the mouse wheel while the JSpinner has focus works just fine (using GTK LookAndFeel).
Testing the software on Microsoft Windows exposed a different behavior:
The JSpinner will not react on mouse wheel movement. LookAndFeels don't seem to be a problem here, as i already tried MetalLookAndFeel on both Linux and Windows.
Any suggestions on how to get this JSpinner reacting on MouseWheelEvents on both OSes?
Thank you.

Hmm im not sure what could be wrong, but here is code designed on windows 7 and it works fine so maybe try it out on yours and see where the code is different:
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
/**
*
* #author David
*/
public class JSpinnerMouse extends JFrame {
private JSpinner jspinner;
public JSpinnerMouse() {
createAndShowUI();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
}
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
JSpinnerMouse jSpinnerMouse = new JSpinnerMouse();
}
});
}
private void createAndShowUI() {
setTitle("JSpinner using mouse wheel");
setSize(300, 300);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
addComponentsToContentPane(getContentPane());
addListeners();
setVisible(true);
}
private void addComponentsToContentPane(Container contentPane) {
jspinner = new JSpinner();
contentPane.add(jspinner);
}
private void addListeners() {
this.addMouseWheelListener(new MouseWheelListener() {
#Override
public void mouseWheelMoved(MouseWheelEvent mwe) {
if (MouseWheelEvent.WHEEL_UNIT_SCROLL == mwe.getScrollType()) {
int value = (int) jspinner.getValue();
if (mwe.getWheelRotation() == -1) {//up
jspinner.setValue(value + 1);
} else {//down
jspinner.setValue(value - 1);
}
}
}
});
}
}
Also to mention, I could not find the getDirection() method in the MouseWheelEvent like you said you are using so i used the getUnitsToScroll() which will return either a positive or negative value depending on the direction. Maybe this is whats causing the trouble. Where did you find a getDirection() method in the MouseWheelEvent Class?

Related

Java AWT Stops listening to input after random lengths of time

(Sorry I can't get a working E.g. of the issue, I need help for my help!)
I'm in the process of creating a custom game engine and have come upon an issue whereby while the game is running - the game stops taking input
I've checked and the program seems to continue running in the background. It also doesn't seem to vary with different machines
(My main device is a Mac Book Pro 2011)
import java.awt.event.*;
import java.io.IOException;
import java.awt.*;
import javax.swing.*;
public class Focus extends JFrame implements KeyListener {
private static final long serialVersionUID = 1L;
char currKey = '\0';
public static void main(String[] args) throws IOException {
SwingUtilities.invokeLater(new Runnable() {public void run() {new UIManager();}});
}
public Focus() throws IOException {
Container contentPane = getContentPane();
contentPane.add(new DrawCanvas());
addKeyListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setFocusable(true);
setVisible(true);
}
private class DrawCanvas extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics pen) {
//Drawloop
if(currKey == 'k') {
//This is the code that randomly stops running
System.out.println("Yo");
}
try {
Thread.sleep(10);
}
catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
#Override
public void keyTyped(KeyEvent e) {
currKey = e.getKeyChar();
}
#Override
public void keyPressed(KeyEvent e) {
currKey = '\0';
}
#Override
public void keyReleased(KeyEvent e) {
}
}
The code looks right to me (But then, it always does) and the only possible tripping point is that AWT is Instantiated in Main, Run in UIManager and the movement code resides in player though I don't know enough about AWT to know whether this would be the case and relocating the code in a backup lead to a program crash. Any help would be greatly appreciated.
Turns out it was an issue with Java and MacOS key repeats- fixed in a newer Java version
To fix update java

Using Python to get global keystrokes for java

I'm making a program for a game HUD GUI but java cant get global keystrokes when the window isn't in focus so, and i dont want to do any black magic with jnativeinterface as i need it to work on both Linux and windows. My idea for getting around this was to pipe output from python to java but I'm not entirely sure how to do so.
here's my code so far for reference:
I've tried assigning a java key-listener to a none existent window just because i was curious and it didn't work.
package main;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class MainThread extends JFrame implements KeyListener{
private static final long serialVersionUID = 1L;
public static void main(String[] args) throws Exception {
System.out.println("Jeffrey was here");
JFrame win = new JFrame();
JPanel wind = new JPanel();
win.add(wind);
win.setDefaultCloseOperation(EXIT_ON_CLOSE);
win.setVisible(true);
win.setLocation(500, 500);
win.setResizable(false);
win.setSize(300,50);
win.setAlwaysOnTop(true);
win.setTitle("Mouse Cordinates");
JLabel xCord = new JLabel("");
JLabel yCord = new JLabel("");
wind.add(xCord);
wind.add(yCord);
while(true) {
Thread.sleep(30);
PointerInfo mouse = MouseInfo.getPointerInfo();
Point poin = mouse.getLocation();
xCord.setText("X cordinates: " + (int) poin.getX());
yCord.setText("Y cordinates: " + (int) poin.getY());
}
}
#Override
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
int key = arg0.getKeyCode();
if(key == KeyEvent.VK_W) {
System.out.print("w pressed");
}
}
#Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
i need it to detect when the key is pressed without the window is in focus.
There are already existing libraries that give you this option (i know this is not exactly what you are looking for (python and stuff), but it might be a solution to your problem). Take a look at kristian's system hook code snippet:
public static void main(String[] args) {
// might throw a UnsatisfiedLinkError if the native library fails to load or a
// RuntimeException if hooking fails
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(true);
keyboardHook.addKeyListener(new GlobalKeyAdapter() {
#Override
public void keyPressed(GlobalKeyEvent event) {
System.out.println(event);
if (event.getVirtualKeyCode() == GlobalKeyEvent.VK_ESCAPE)
run = false;
}
#Override
public void keyReleased(GlobalKeyEvent event) {
System.out.println(event);
}
});
And of course there is also the JNativeHook option.
Some other already existing questions to take a look:
How to capture global key presses in java
How can I write a key listener to track all keystrokes in Java?

Why does my AWT/swing GUI JAR capture stylus event data only in a specific region of the screen on a Windows 8.1 tablet?

QUESTION SUMMARY: I generated a .JAR file using Netbeans 7.2.1 for a Java Swing/AWT program developed on Windows 7 (Java version 1.8.0_40), that helps collect user handwriting from the screen. It runs fine on a Windows 7 notebook PC but due to some reason captures handwriting data only on a specific region of the screen on a Windows 8.1 tablet (Java version 1.8.0_45). Could someone kindly tell me why this is happening?
DETAILS: I have a requirement of collecting online handwriting samples (i.e. those acquired from electronic devices like a tablet PC using a pen/stylus and writing surface) for some analysis
Being new to developing programs of this nature, I read up about it on the web and decided to use the Java Swing/AWT toolkits
A person's handwriting is composed of strokes which are in turn composed of points. My objective was to capture:
- the X- and Y-coordinates of a point on the screen
- the timestamp of creation of this point
- the stroke's start-time, end-time and color (color not too important)
To this end I wrote the following program using Netbeans 7.2.1 IDE with Java 1.8.0_40 on a Windows 7 Home Basic OS
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package handwritingsamplerawt;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class HandwritingSamplerAWT {
static JFrame frame;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
CreateAndShowGUI();
}
});
}
private static void CreateAndShowGUI() {
frame = new JFrame("Writing Surface v0.1");
frame.getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(Color.LIGHT_GRAY);
frame.pack();
frame.add(new MyPanel());
frame.setVisible(true);
}
}
class MyPanel extends JPanel{
private int x,y;
static int strokeIndex;
private long reducedMillis;
private ArrayList<StrokeInfo> strokes;
private JButton btnSave;
public MyPanel() {
MyPanel.strokeIndex=0;
this.reducedMillis = 1435800000000L;
this.strokes = new ArrayList<>();
this.btnSave = new JButton("SAVE SAMPLE");
this.btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
WriteCoordinates();
}
});
this.add(this.btnSave);
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
x=e.getX();
y=e.getY();
SaveCoordinates(x,y,"PRESSED");
repaint();
}
});
addMouseMotionListener(new MouseAdapter() {
public void mouseDragged(MouseEvent e) {
x=e.getX();
y=e.getY();
SaveCoordinates(x,y,"DRAGGED");
repaint();
}
});
addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
x=e.getX();
y=e.getY();
SaveCoordinates(x,y,"RELEASED");
repaint();
}
});
}
void SaveCoordinates(int xCoordinate, int yCoordinate, String actionIndicator){
try {
Calendar cal = Calendar.getInstance();
Date currDate = cal.getTime();
double timeStamp=(double)(currDate.getTime()-reducedMillis);
PointInfo pointObj = new PointInfo(xCoordinate, yCoordinate, timeStamp);
switch (actionIndicator) {
case "PRESSED":
StrokeInfo newStroke = new StrokeInfo();
newStroke.points.add(pointObj);
strokes.add(newStroke);
break;
case "DRAGGED":
strokes.get(strokeIndex).points.add(pointObj);
break;
case "RELEASED":
strokeIndex+=1;
break;
}
} catch (Exception ex){
String errMsg = ex.getMessage();
System.out.println(errMsg);
}
}
void WriteCoordinates() {
try {
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String currTimeString = dateFormat.format(cal.getTime());
DecimalFormat decFormat = new DecimalFormat("#");
decFormat.setMaximumFractionDigits(2);
FileWriter writer = new FileWriter("D:\\HandwritingCaptures\\HandwritingText\\"+currTimeString+".txt");
SetStrokeAttributes(strokes);
ListIterator<PointInfo> pointItr;
if (strokes.isEmpty()==false) {
for (int index = 0; index < strokeIndex; index++) {
writer.write(strokes.get(index).colour);
writer.append('\t');
writer.write(decFormat.format( strokes.get(index).startTime));
writer.append('\t');
writer.write(decFormat.format( strokes.get(index).endTime));
writer.append('\n');
pointItr = strokes.get(index).points.listIterator();
while (pointItr.hasNext()) {
PointInfo currPoint = pointItr.next();
writer.write(String.valueOf(currPoint.x));
writer.append('\t');
writer.write(String.valueOf(currPoint.y));
writer.append('\t');
writer.write(decFormat.format(currPoint.timestamp));
writer.append('\n');
}
writer.append('#');
writer.append('\n');
}
}
writer.close();
SaveScreenshot("D:\\HandwritingCaptures\\Screenshots\\"+currTimeString+".png");
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
void SetStrokeAttributes(ArrayList<StrokeInfo> strokeList) {
double startTime, endTime;
String colour;
StrokeInfo tmpStroke;
ArrayList<PointInfo> points;
if (strokeList.isEmpty() == false) {
for (int index = 0; index < strokeList.size(); index++) {
tmpStroke = strokeList.get(index);
points = tmpStroke.points;
tmpStroke.colour = "black";
tmpStroke.startTime=points.get(0).timestamp;
tmpStroke.endTime=points.get(points.size()-1).timestamp;
strokeList.set(index, tmpStroke);
}
}
}
void SaveScreenshot(String imgFilePath){
try {
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "png", new File(imgFilePath));
} catch (IOException | AWTException ex) {
System.out.println(ex.getMessage());
}
}
public Dimension getPreferredSize() {
return new Dimension(1366,768);
}
protected void paintComponent(Graphics g) {
super.paintComponents(g);
g.setColor(Color.BLACK);
g.drawLine(x, y, x, y);
}
}
class PointInfo {
int x,y;
double timestamp;
public PointInfo(int px, int py, double ts) {
this.x=px;
this.y=py;
this.timestamp=ts;
}
}
class StrokeInfo {
ArrayList<PointInfo> points;
double startTime, endTime;
String colour;
public StrokeInfo() {
points= new ArrayList<>();
}
}
I generated the .jar file using the IDE itself (Project Properties-> Build-> Packaging-> Compress JAR file)
Then copied the .jar file to a HP EliteBook 2730P Notebook PC with JRE 1.7.0.800 and Windows 7 Pro OS (32-bit) where it ran fine collecting handwriting strokes from all areas of the screen
But when I copied the same .jar to a HP Elite x2 1011 G1 tablet with JRE 1.8.0_45 and Windows 8.1 (64-bit) and ran it, I found that strangely it captures stylus inputs ONLY from a specific region of the screen - more specifically towards the upper right. It is completely non-responsive on the other areas
Could someone please help me understand why this is happening? Would have posted couple screenshots here but my low reputation prevents me from doing so.
ADDITIONAL THOUGHTS: Would it be better to use .NET or Java FX for developing such a tool for using in a Windows 8.1 environment?
Your panel seems to have a fixed size:
return new Dimension(1366,768);
Is the resolution of your tablet bigger than that?
Edit:
This should help:
private static void CreateAndShowGUI() {
frame = new JFrame("Writing Surface v0.1");
// Using the default BorderLayout here.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(Color.LIGHT_GRAY);
frame.getContentPane().add(new MyPanel(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
However there are still problems with your layout, like the "Save" button jumping around. You should take a look at this tutorial:
https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html
The fact that the problem could be related to the hardcoded dimensions became clear on seeing the behavior of the .jar file upon running
The tablet had a higher resolution (1920 x 1080 pixels - found by checking the screen resolution through a right click on the desktop) than the machine I had initially run the program on (1366 x 768 pixels). The dimensions of the writable area towards the upper right corner were infact true to the hardcoded dimensions
Ergo, I modified the overridden method getPreferredSize() in the following manner:
public Dimension getPreferredSize() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return new Dimension((int)screenSize.getWidth(),(int)screenSize.getHeight());
}
This causes the preferred size components to take on the effective height and width of the screen of the device the .jar is executed on. This is important because depending on the layout manager used the treatment of the above method by it does differ
The "SAVE SAMPLE" button intermittently still seems to cast its images (non-clickable) on other areas of the screen - this probably might have something to do with the layout manager handling of the UI components. Shall add an edit for that issue too once I find a solution

JInternalFrame selection

I have a JDesktopPane containing some JInternalFrames. I want some menus on the menubar to be activated only when one of the JInternalFrames is selected. I've tried using VetoableChangeListener, with the following code in it:
JInternalFrame selectedFrame = desk.getSelectedFrame();
if ((selectedFrame != null)) {
imageMenu.setEnabled(Boolean.TRUE);
} else {
imageMenu.setEnabled(Boolean.FALSE);
}
But the results are not what I expected - for example, the menu is enabled only the second time I add a frame. when I close all frames, it remains enabled.
How can I make this work?
you have to read basic tutorial about JInternalFrames with link to the InternalFrameListener,
but another and look like as better way is programatically to know those event in all cases and evety times is by adding PropertyChangeListener as shows examples Getting All Frames in a JDesktopPane Container, by adding PropertyChangeListener you can listeng for these events
Add an InternalFrameListener to each internal frame added to the desktop pane, and each time an event is triggered, execute the code you have shown in your question.
This code could be better written though:
setEnabled takes a primitive boolean as argument, not a java.lang.Boolean. Use true and false rather than Boolean.TRUE and Boolean.FALSE.
The expression (selectedFrame != null) evaluates as a boolean. Just write
imageMenu.setEnabled(selectedFrame != null);
instead of
if ((selectedFrame != null)) {
imageMenu.setEnabled(Boolean.TRUE);
} else {
imageMenu.setEnabled(Boolean.FALSE);
}
I would just create a custom event and fire it when a JInternalFrame gets focus (isActivated).
The menu items would listen for this event, intercept it and set their status enabled or disabled accordingly.
The advantage here is that you don't have to handle what menu items should be available for which types of internal frames, just fire the appropriate event. It'll make your life easier if you add more internal frames in the future.
This answer is based on the answer by #mKorbel. This example shows one of the ways to detect focus between internal frames as is demonstrated here:
package com.apexroot.sandbox;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
/**
* author grants unlimited license to modify, reuse and redistribute. based on
* the suggestion by #mKorbel on stackoverflow at
* http://stackoverflow.com/questions/7219860/jinternalframe-selection
* please keep a URL to the original version in the source code.
* http://javajon.blogspot.com/2015/08/windowfocuslistener-for-jinternalframe.html
*
* #author Apexroot
*/
public class InternalFrameFocusListenerExample {
public static final String INTERNAL_FRAME_FOCUS_EVENT_PROPERTY = "selected";
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
final JFrame jFrame = new JFrame();
final JDesktopPane jDesktopPane = new JDesktopPane();
final JInternalFrame[] jInternalFrames = new FocusInternalFrame[3];
for (int i = 0; i < jInternalFrames.length; i++) {
jInternalFrames[i] = new FocusInternalFrame();
}
jFrame.dispose();
jFrame.setContentPane(jDesktopPane);
jDesktopPane.setPreferredSize(new Dimension(400, 200));
jFrame.pack();
jFrame.setVisible(true);
for (int i = 0; i < jInternalFrames.length; i++) {
jDesktopPane.add(jInternalFrames[i]);
jInternalFrames[i].setLocation(10 + 60 * i, 10 + 40 * i);
jInternalFrames[i].setVisible(true);
}
}
});
}
public static class FocusInternalFrame extends JInternalFrame {
public FocusInternalFrame() {
final JLabel jLabel = new JLabel("placeholder for pack();");
setContentPane(jLabel);
pack();
this.addPropertyChangeListener(
INTERNAL_FRAME_FOCUS_EVENT_PROPERTY,
new LabelFocusListener(jLabel));
}
}
private static class LabelFocusListener implements PropertyChangeListener {
private final JLabel jLabel;
public LabelFocusListener(JLabel jLabel) {
this.jLabel = jLabel;
}
#Override
public void propertyChange(PropertyChangeEvent evt) {
// please keep a URL to the original version in the source code.
// http://javajon.blogspot.com/2015/08/windowfocuslistener-for-jinternalframe.html
if (INTERNAL_FRAME_FOCUS_EVENT_PROPERTY.equals(
evt.getPropertyName())) {
final Object oldValue = evt.getOldValue();
final Object newValue = evt.getNewValue();
if (oldValue instanceof Boolean
&& newValue instanceof Boolean) {
boolean wasInFocus = (Boolean) oldValue;
boolean isInFocus = (Boolean) newValue;
if (isInFocus && !wasInFocus) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
// focus gained
jLabel.setText("focus gained");
}
});
} else if (wasInFocus && !isInFocus) {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
// focus lost
jLabel.setText("focus lost");
}
});
}
}
}
}
}
}

Java: Strange behavior of JEditorPane wrapped inside JScrollPane

I'm trying to build a simple help system to my software.
The help system built from JEditorPane(Loaded with HTML file) wrapped inside of JScrollPane, inside of the same window there is a JLabel.
When the user move the mouse over the JEditorPane on a specific word - more explanations appear in the JLabel.
I succeed doing it, but the problem is, that for some reason it work just on the beginning of the text.(the HTML file is long and must be scrolled...)
After i scroll down the page and hover over a word, it throw me BadLocationException.
On the code below there is a JEditorPane wrapped inside JScrollPane.
When the user move the mouse it print the current letter which the mouse point on.(on the help system i find the value of the word by this position and print explanations to the JLabel according to it)
But, as i said it work just on the beginning of the text.
Why ?
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.Point;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.text.BadLocationException;
public class JEditorPaneTestApp extends JFrame {
private JEditorPane editorPan;
private JScrollPane scrollPan;
public JEditorPaneTestApp() {
super();
try {
editorPan = new javax.swing.JEditorPane("file:///path/toHTML/file/helpFile.html");
}
catch (IOException e) {e.printStackTrace();}
scrollPan = new JScrollPane(editorPan);
this.add(scrollPan);
editorPan.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(java.awt.event.MouseEvent evt) {
Point p = new Point(evt.getX(), evt.getY());
int pos = editorPan.viewToModel(p);
try {
System.out.println(editorPan.getText(pos--, pos).charAt(0));
}
catch (BadLocationException e1) {
System.out.println("Invalid location");/* e1.printStackTrace();*/
}
}
});
scrollPan.setViewportView(editorPan);
this.add(scrollPan);
//
this.getContentPane().setLayout(new LayoutManager() {
#Override public Dimension preferredLayoutSize(Container arg0) {return null;}
#Override public Dimension minimumLayoutSize(Container arg0) {return null;}
#Override public void removeLayoutComponent(Component arg0) {}
#Override public void addLayoutComponent(String arg0, Component arg1) {}
#Override public void layoutContainer(Container conter) {
scrollPan.setBounds(0, 0, conter.getWidth(), conter.getHeight());
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
JEditorPaneTestApp test = new JEditorPaneTestApp();
}
}
Thanks
System.out.println(editorPan.getText(pos--, pos).charAt(0));
should be:
System.out.println(editorPan.getText(pos--, 1).charAt(0));

Categories

Resources