Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JOptionPane和图_Java_Graph_Joptionpane - Fatal编程技术网

Java JOptionPane和图

Java JOptionPane和图,java,graph,joptionpane,Java,Graph,Joptionpane,我想知道如何让JOptionPane能够滚动直方图。我设法让JOptionPane显示我的直方图,唯一的问题是你不能滚动浏览它。窗口延伸到屏幕底部,仅显示图形的一半 注意:这仅在读取包含300+个介于0和130之间的整数的大型输入文件时发生。程序将无法识别任何其他内容 输入值: 54 38 42 40 34 51 54 58 61 55 54 42 40 34 51 54 54 54 38 60 42 40 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54

我想知道如何让JOptionPane能够滚动直方图。我设法让JOptionPane显示我的直方图,唯一的问题是你不能滚动浏览它。窗口延伸到屏幕底部,仅显示图形的一半

注意:这仅在读取包含300+个介于0和130之间的整数的大型输入文件时发生。程序将无法识别任何其他内容

输入值:

54 38 42 40 34 51 54 58 61 55 54 42 40 34 51 54 54 54 38 60 42 40 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 32 28 24 18 9 4. 22 31 38 34 41 32 28 24 18 31 38 34 41 32 28 24 18 31 38 34 41 32 28 31 38 35 51 34 41 56 63 59 66 48 46 58 41 56 63 51 59 48 46 58 41 56 63 53 52 58 48 49 58 41 56 63 51 52 59 58 66 63 71 69 70 72 67 66 63 71 74 75 69 73 78 72 67 63 71 74 59 56 69 70 78 72 66 71 74 69 70 78 72 67 63 59 58 57 64 71 72 67 63 59 64 71 73 79 75 78 72 67 63 59 63 71 73 75 78 72 67 63 57 73 77 75 78 72 67 71 73 77 75 78 81 83 87 84 91 92 90 84 76 83 82 89 78 81 83 87 84 91 92 90 84 78 85 82 89 96 91 78 81 83 86 82 91 92 90 84 85 82 89 92 96 91 95 97 98 91 95 97 93 87 85 94 89 92 96 93 96 97 98 98 100 102 95 97 93 87 88 89 93 84 89 92 95 95 95 97 94 91 87 84 80 90 82 80 73 75 70 74 74 75 70 66 63 71 69 70 72 67 66 63 71 55 59 53 58 52 67 63 71 74 59 56 69 70 58 62 56 51 54 49 60 68 62 67 63 59 58 57 64 44 38 42 40 34 51 54 55 54 42 40 34 51 54 54 54 38 42 31 38 34 41 32 28 24 18 31 38 34 41 32 28 24 18 31 38 34 41 32 28 31 28 35 41 34 37 26 23 29 40 45 46 39 31 40 38 29 34 三十六

import javax.swing.*;
导入java.io.File;
导入java.io.FileNotFoundException;
导入java.util.Scanner;
导入javax.swing.JFileChooser;
导入javax.swing.JOptionPane;
公共舱凉爽天气
{
静态JFileChooser选择器;
静态扫描仪;
公共静态void main(字符串[]args)引发FileNotFoundException
{
//获取输入文件
文件输入文件;
选择器=新的JFileChooser(“.”);
int status=selector.showOpenDialog(空);
if(状态!=JFileChooser.APPROVE\u选项)
{
showMessageDialog(null,“关闭程序”);
系统出口(0);
}
inputFile=selecter.getSelectedFile();
showMessageDialog(null,“打开:“+inputFile.getName()”);
//创建数组
int[]temps=readData(inputFile);
//打印直方图
showMessage(temps);
}
//以下方法使用数据创建并填充数组
//从输入文件
公共静态int[]readData(文件inputFile)引发FileNotFoundException
{
in=新扫描仪(输入文件);
in.useDelimiter(“[^0-9/s]+”);
int[]temps=新int[131];
整数计数=0;
int-num;
做
{
num=in.nextInt();
计数++;
temps[num]++;
} 
while(in.hasNextInt());
showMessageDialog(null,“读取的条目数:“+count”);
返回临时工;
}
公共静态void showMessage(int[]temps)
{ 
字符串输出=“Temp\tCount\tVisual”;
//对于每个数组元素,输出直方图中的条形图
用于(int计数器=0;计数器0)
{
输出+=“\n”+计数器+“\t”+临时[计数器]+“\t”;
//星号打印条
对于(int stars=0;stars
这是处理异常时用于UI的
作业窗格
,但原理与
JScrollPane

JLabel label = new JLabel(e.getLocalizedMessage() + ":");
label.setFont(getFont().deriveFont(Font.BOLD));
label.setAlignmentX(JLabel.LEFT_ALIGNMENT);

StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));

JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setFont(getFont());
textArea.setTabSize(2);
textArea.setText(writer.toString());
SwingUtilities.invokeLater(() -> textArea.setCaretPosition(0));

JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setAlignmentX(JScrollPane.LEFT_ALIGNMENT);
scrollPane.setPreferredSize(new Dimension(500, 200));

JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(label);
panel.add(Box.createVerticalStrut(5));
panel.add(scrollPane);

JOptionPane.showMessageDialog(this, panel, ApplicationInfo.getAppName(), JOptionPane.ERROR_MESSAGE);

JTextArea
必须放入
JScrollPane
我还在学习,你能解释一下你的意思吗?查看
JScrollPane
类并搜索如何使用它的教程。
JLabel label = new JLabel(e.getLocalizedMessage() + ":");
label.setFont(getFont().deriveFont(Font.BOLD));
label.setAlignmentX(JLabel.LEFT_ALIGNMENT);

StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));

JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setFont(getFont());
textArea.setTabSize(2);
textArea.setText(writer.toString());
SwingUtilities.invokeLater(() -> textArea.setCaretPosition(0));

JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setAlignmentX(JScrollPane.LEFT_ALIGNMENT);
scrollPane.setPreferredSize(new Dimension(500, 200));

JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(label);
panel.add(Box.createVerticalStrut(5));
panel.add(scrollPane);

JOptionPane.showMessageDialog(this, panel, ApplicationInfo.getAppName(), JOptionPane.ERROR_MESSAGE);
    JTextArea outputArea = new JTextArea();
    outputArea.setText(output);
    outputArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(outputArea);
    scrollPane.setAlignmentX(JScrollPane.LEFT_ALIGNMENT);
    scrollPane.setPreferredSize(new Dimension(500, 200));
    JOptionPane.showMessageDialog( null, scrollPane, "CoolWeather Histogram", JOptionPane.INFORMATION_MESSAGE);
    System.exit( 0 );