- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在网上搜索为什么我的文本区域不在 JScrollPane 中滚动的答案? JScrollPane 旋钮根据文本区域中的行数调整其大小。它看起来像它的工作,但我无法滚动它。任何建议将不胜感激!
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.DecimalFormat;
//import java.util.regex.Pattern;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
//import javax.swing.SwingWorker;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
public class Output_Window extends JFrame implements Runnable {
public boolean keepRefreshing = true;
private JTextArea chosen_settings;
public JTextArea package_status;
private JTextArea program_status;
private JTextArea efficiency;
private JTextArea emptyPackages;
private JTextArea skipped_cases;
private JTextArea package_status_title;
private JTextArea program_status_title;
private JTextArea efficiency_title;
private JTextArea chosen_settings_title;
private JTextArea emptyPackagesTitle;
private JTextArea skipped_cases_title;
private JScrollPane emptyPackageScroll;
private JScrollPane skipped_cases_scroll;
private Font titleFont = new Font("Arial", Font.BOLD, 14);
// private SwingWorker<Boolean, Integer> worker = null;
private JPanel panel = new JPanel(new GridBagLayout());
private long startTime = System.nanoTime();
private long previousTime = System.nanoTime();
private long currentTime = System.nanoTime();
private long elapsedTime;
private long totalTime = 0;
private long packageStart;
private long packageElapsed;
private static boolean start = false;
private long packageAverageTime = 0;
private long totalPackageTime = 0;
private int numPackages = 0;
private double totalEmpty = 0;
private double emptyPercentage = 0;
private boolean first = true;
private int skippedCases = 0;
// private long estimatedTimeRemaining = 0;
private static double totalPackages = 0;
private int sec_TT = 0;
private int min_TT = 0;
private int hour_TT = 0;
private int day_TT = 0;
private int sec_PT = 0;
private int min_PT = 0;
private int hour_PT = 0;
private int day_PT = 0;
private int sec_PAT = 0;
private int min_PAT = 0;
private int hour_PAT = 0;
private int day_PAT = 0;
// private Pattern pattern;
private String text = "";
private String text2 = "";
Thread windowThread;
/**
* Window for displaying output
*/
private static final long serialVersionUID = 2462095488215034654L;
public Output_Window() {
setPreferredSize(new Dimension(1200, 900));
// setSize(new Dimension(1200, 900));
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
GridBagConstraints c = new GridBagConstraints();
setResizable(false);
setTitle("Athena Test Automation Tool");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//center it on the screen
String dir = System.getProperty("user.dir");
ImageIcon icon = new ImageIcon(dir + "\\AthenaIcon.png");
setIconImage(icon.getImage());
init();
c.weighty = 1;
c.weightx = 1;
c.insets = new Insets(10, 10, 10, 10);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTHWEST;
panel.add(chosen_settings_title, c);
c.gridx = 0;
c.gridy = 1;
panel.add(chosen_settings, c);
c.gridx = 0;
c.gridwidth = 1;
c.gridy = 2;
panel.add(program_status_title, c);
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 1;
// c.fill = GridBagConstraints.NONE;
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(program_status, c);
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 1;
panel.add(package_status_title, c);
c.gridx = 0;
c.gridy = 5;
c.gridwidth = 1;
panel.add(package_status, c);
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 1;
c.anchor = GridBagConstraints.NORTHEAST;
panel.add(efficiency, c);
c.gridx = 1;
c.gridy = 0;
panel.add(efficiency_title, c);
c.gridx = 1;
c.gridy = 4;
panel.add(emptyPackagesTitle, c);
c.gridx = 1;
c.gridy = 5;
panel.add(emptyPackageScroll, c);
c.gridx = 1;
c.gridy = 2;
panel.add(skipped_cases_title, c);
c.gridx = 1;
c.gridy = 3;
panel.add(skipped_cases_scroll, c);
panel.setBackground(Color.WHITE);
add(panel);
pack();
setVisible(true);
setLocationRelativeTo(null);
//panel.update(panel.getGraphics());
windowThread = new Thread(this);
windowThread.setPriority(Thread.MAX_PRIORITY);
windowThread.start();
}
public void init() {
chosen_settings = new JTextArea();
chosen_settings.setEditable(false);
chosen_settings.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
chosen_settings.setMargin(new Insets(0, 10, 0, 0));
program_status = new JTextArea();
program_status.setEditable(false);
program_status.setLineWrap(true);
program_status.setWrapStyleWord(true);
program_status.setPreferredSize(new Dimension(700, 280));
program_status.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
package_status = new JTextArea();
package_status.setEditable(false);
package_status.setLineWrap(true);
package_status.setWrapStyleWord(true);
package_status.setPreferredSize(new Dimension(700, 290));
package_status.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
efficiency = new JTextArea();
efficiency.setEditable(false);
efficiency.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
//ignore this textarea
skipped_cases = new JTextArea();
skipped_cases.setEditable(false);
skipped_cases.setLineWrap(true);
skipped_cases.setWrapStyleWord(true);
skipped_cases.setPreferredSize(new Dimension(50, 280));
emptyPackages = new JTextArea(10,10);
emptyPackages.setEditable(false);
emptyPackages.setLineWrap(true);
emptyPackages.setWrapStyleWord(true);
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
emptyPackages.append("TESTING\n");
// emptyPackages.setPreferredSize(new Dimension(50, 290));
// emptyPackages.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
DefaultCaret caret = (DefaultCaret) emptyPackages.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
emptyPackagesTitle = new JTextArea();
emptyPackagesTitle.setEditable(false);
package_status_title = new JTextArea();
package_status_title.setEditable(false);
program_status_title = new JTextArea();
program_status_title.setEditable(false);
chosen_settings_title = new JTextArea();
chosen_settings_title.setEditable(false);
efficiency_title = new JTextArea();
efficiency_title.setEditable(false);
skipped_cases_title = new JTextArea();
skipped_cases_title.setEditable(false);
chosen_settings_title.setFont(titleFont);
chosen_settings_title.append("Chosen Locations and Environment:");
chosen_settings.append("Chosen Target Network Location: " + Athena_Test_Automation_Framework.targetNetworkDirectory);
chosen_settings.append("\nChosen Application Server: "+ Athena_Test_Automation_Framework.chosenAthenaApplicationServer);
chosen_settings.append("\nChosen DB Server: " + Athena_Test_Automation_Framework.chosenAthenaDatabaseServer);
chosen_settings.append("\nType of Environment: " + Athena_Test_Automation_Framework.chosenAthenaEnvironment);
if(Athena_Test_Automation_Framework.chosenNetworkStorageLocation.length() != 0){
chosen_settings.append("\nNetwork Storage Location: " + Athena_Test_Automation_Framework.chosenNetworkStorageLocation);
}else{
chosen_settings.append("\nNetwork Storage Location: N/A");
}
emptyPackagesTitle.setFont(titleFont);
emptyPackagesTitle.append("Empty Distribution Packages: (Total: 0/0 -- %0.0)");
program_status_title.setFont(titleFont);
program_status_title.append("Program Status:");
package_status_title.setFont(titleFont);
package_status_title.append("Package Status: Processing Package... N/A");
skipped_cases_title.setFont(titleFont);
skipped_cases_title.append("Skipped TestCases: (Total: 0)");
efficiency_title.setFont(titleFont);
efficiency_title.append("Time Status:");
efficiency.append("Total Time: 0:0:0:0");
efficiency.append("\nCurrent Package Time: 0:0:0:0");
efficiency.append("\nAverage Package Time: 0:0:0:0");
//efficiency.append("\nEstimated Time Remaining: 0:0:0:0");
efficiency.append("\n\n");
emptyPackageScroll = new JScrollPane(emptyPackages);
emptyPackageScroll.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
emptyPackageScroll.setSize(new Dimension(50,290));
skipped_cases_scroll = new JScrollPane(skipped_cases);
skipped_cases_scroll.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
skipped_cases_scroll.setPreferredSize(new Dimension(50,280));
}
/**
* Updates text of JTextArea
*
* @param text
* @param addBreak
* TODO
*/
public void updateWindow(String text, boolean addBreak, int place) {
String textToAppend = text;
if (addBreak) {
textToAppend = textToAppend + "\n";
}
if (place == 0) {
package_status.append(textToAppend);
} else if(place == 1) {
program_status.append(textToAppend);
}else if(place == 2) {
skipped_cases.append(textToAppend);
replaceLineInWindow("Total: " + (skippedCases++), "Total: " + skippedCases, 2);
}else if(place == 5){
emptyPackages.append(textToAppend);
double oldPercentage = emptyPercentage;
DecimalFormat twoDForm = new DecimalFormat("##.##");
emptyPercentage = Double.valueOf(twoDForm.format(((++totalEmpty)/totalPackages)*100));
if(first){
first = false;
replaceLineInWindow("Total: 0/0 -- %" + oldPercentage, "Total: " + (int)(totalEmpty) + " -- %" + emptyPercentage, 5);
}else{
replaceLineInWindow("Total: " + (int)(totalEmpty-1) + " -- %" + oldPercentage, "Total: " + (int)(totalEmpty) + " -- %" + emptyPercentage, 5);
}
}
}
/**
* Replaces line of text in JTextArea
*
* @param text
* @param text2
*/
public void replaceLineInWindow(String text, String text2, int place) {
if (place == 0) {
String textFromArea = package_status.getText();
String textFromArea2 = textFromArea.replace(text, text2);
package_status.setText(textFromArea2);
} else if(place == 1) {
String textFromArea = program_status.getText();
String textFromArea2 = textFromArea.replace(text, text2);
program_status.setText(textFromArea2);
} else if(place == 2){
String textFromArea = skipped_cases_title.getText();
String textFromArea2 = textFromArea.replace(text, text2);
skipped_cases_title.setText(textFromArea2);
} else if(place == 3){
String textFromArea = chosen_settings.getText();
String textFromArea2 = textFromArea.replace(text, text2);
chosen_settings.setText(textFromArea2);
} else if(place == 4){
String textFromArea = package_status_title.getText();
String textFromArea2 = textFromArea.replace(text, text2);
package_status_title.setText(textFromArea2);
} else if(place == 5){
String textFromArea = emptyPackagesTitle.getText();
String textFromArea2 = textFromArea.replace(text, text2);
emptyPackagesTitle.setText(textFromArea2);
}
}
public void restartTextArea(int textarea) {
if (textarea == 0) {
package_status.setText("");
} else {
program_status.setText("");
}
}
/**
* Updates text of JTextArea
*
* @param text
*/
public void updateEfficiency() {
//starts a new package clock 0:0:0:0
String textFromArea2;
currentTime = System.nanoTime();
elapsedTime = (currentTime - previousTime)/1000000000;
if(start){
start = false;
packageStart = System.nanoTime();
totalPackageTime += packageElapsed;
if(numPackages != 0){
packageAverageTime = totalPackageTime / numPackages;
}
if(numPackages < totalPackages){
numPackages++;
}
if(numPackages == 1){
replaceLineInWindow("N/A", numPackages + "/" + (int)totalPackages, 4);
}else{
replaceLineInWindow((numPackages-1) + "/", numPackages + "/", 4);
}
min_PAT = 0;
hour_PAT = 0;
day_PAT = 0;
min_PT = 0;
hour_PT = 0;
day_PT = 0;
sec_PAT = (int) packageAverageTime;
while (sec_PAT > 60) {
sec_PAT -= 60;
min_PAT++;
if (min_PAT > 60) {
hour_PAT++;
min_PAT = 0;
} else if (hour_PAT > 24) {
day_PAT++;
hour_PAT = 0;
}
}
}
if(elapsedTime >= 1){
previousTime = currentTime;
totalTime = (currentTime - startTime) / 1000000000;
String textFromArea = efficiency.getText();
sec_TT = (int) totalTime % 60;
if (sec_TT == 0) {
min_TT++;
} else if (min_TT % 60 == 0 && min_TT != 0) {
hour_TT++;
min_TT = 0;
} else if (hour_TT % 24 == 0 && hour_TT != 0) {
day_TT++;
hour_TT = 0;
}
if(numPackages != 0){
packageElapsed = (currentTime - packageStart) / 1000000000;
sec_PT = (int) packageElapsed % 60;
if (sec_PT == 0 && packageElapsed != 0) {
min_PT++;
} else if (min_PT % 60 == 0 && min_PT != 0) {
hour_PT++;
min_PT = 0;
} else if (hour_PT % 24 == 0 && hour_PT != 0) {
day_PT++;
hour_PT = 0;
}
}
textFromArea2 = textFromArea.replaceAll("Total Time: [0-9:]+", "Total Time: " + day_TT + ":" + hour_TT + ":" + min_TT + ":" + sec_TT);
textFromArea2 = textFromArea2.replaceAll("Current Package Time: [0-9:]+", "Current Package Time: " + day_PT + ":" + hour_PT + ":" + min_PT + ":" + sec_PT);
textFromArea2 = textFromArea2.replaceAll("Average Package Time: [0-9:]+", "Average Package Time: " + day_PAT + ":" + hour_PAT + ":" + min_PAT + ":" + sec_PAT);
efficiency.setText(textFromArea2);
}
}
/**
* Continuously updates text of JTextArea
* call whenever updateOutput() or replaceLineInWindow() is called
*
* @param text
*/
public void updateDots(){
text = package_status_title.getText();
if(text.contains("Processing Package ")){
text2 = text.replace("Processing Package ", "Processing Package. ");
}else if(text.contains("Processing Package. ")){
text2 = text.replace("Processing Package. ", "Processing Package.. ");
}else if(text.contains("Processing Package.. ")){
text2 = text.replace("Processing Package.. ", "Processing Package...");
}else if(text.contains("Processing Package...")){
text2 = text.replace("Processing Package...", "Processing Package ");
}else{
text2 = text;
}
package_status_title.setText(text2);
try {
String lineText;
String lineText2;
int line = package_status.getLineCount() - 2;
if(line == 10){
line = 8;
}
int lineStart = package_status.getLineStartOffset(line);
int lineEnd = package_status.getLineEndOffset(line);
lineText = package_status.getText(lineStart, lineEnd - lineStart);
if(lineText.contains(". ")){
lineText2 = lineText.replace(". ", ".. ");
package_status.replaceRange(lineText2, lineStart, lineEnd);
}else if(lineText.contains(".. ")){
lineText2 = lineText.replace(".. ", "...");
package_status.replaceRange(lineText2, lineStart, lineEnd);
}else if(lineText.contains("...")){
lineText2 = lineText.replace("...", ". ");
package_status.replaceRange(lineText2, lineStart, lineEnd);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
public static void setPackageStart() {
start = true;
}
public static void setTotalPackages(int num) {
totalPackages = num;
}
public void run() {
long previousTime = System.nanoTime();
long currentTime = System.nanoTime();
long elapsedTime = (currentTime - previousTime) /1000000000;
while (keepRefreshing) {
currentTime = System.nanoTime();
elapsedTime = (currentTime - previousTime) /1000000000;
// updateEfficiency();
if(elapsedTime >= 1){
previousTime = currentTime;
// if(numPackages != 0){
// updateDots();
// }
if(panel == null){
keepRefreshing = false;
}else{
panel.revalidate();
panel.update(panel.getGraphics());
panel.repaint();
}
}
}
}
}
最佳答案
您已经预设了文本区域的 preferredSize
,这意味着,从 JScrollPane
的角度来看,除了 preferredSize
你已经指定了。
相反,设置 JTextArea
的 rows
和 columns
属性,并允许组件本身继续计算自己的 preferredSize
根据需要
不要做...
panel.update(panel.getGraphics());
在 Swing 中,您不控制绘制过程,您永远不需要直接调用 update
或 paint
,也不应该依赖 getGraphics
此外,作为一般规则,Swing 不是线程安全的,这意味着您永远不应在事件调度线程的上下文之外创建或修改任何 UI 组件。您可能会考虑改用 SwingWorker
关于java - 为什么我的 JTextArea 里面的 JScrollPane 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28908433/
在我的应用程序中,我使用 scrape(string url) 方法从网页中抓取链接。可以说它每次都返回我 10 个 url。 我想从每个抓取的 url 中抓取 10 个链接。 长话短说: (第 1
正如标题所说,我需要将 php 放入由 php 回显的 javascript 中 例如: if (something) then (some php)') ?> 这不是真正的代码,只是可能有助于理解
我有一个 ng-repeat 使用 ng-switch 来分隔 ng-repeat 内部的部分,我想在 ng-switch 组上应用一个 orderby 过滤器,但我似乎无法让它工作:
我是 shell 的新手。我不太了解以下功能。这个函数基本上把小时加1。 我想知道为什么开发人员在 $g_current_hour+1 前面放了“10#”。根据我的理解,shell 中的剂量 # 是指
为了在 MongoDB 中对元素进行分组和计数,我已经筋疲力尽了。有很多帖子,但没有一个是我需要的。 这是一个基于以下内容的示例: styvane answer db.VIEW_HISTORICO.a
int main() { int count = 0; string prev = " "; string current; while (cin>>current)
$0表示传递给swift闭包的第一个参数,是swift语言的语法糖。swift会自动为内联闭包提供速记参数名称,可使用$0,$1,$2等名称来引用闭包参数的值。 代码
我想把这个 If 放在宏中,但它总是给我一个错误。我不知道“或”用得是否正确。 Dim SMAT As String SMAT = "blahblahblah" (...) If Ce
这是 JSFiddle 链接:https://jsfiddle.net/fmdsu9Lo/ 我想添加一个悬停功能,以便将鼠标悬停在菜单上将在该菜单选项卡上应用 .current 样式,同时将其从当前打
是否可以在 SQL 中执行类似的操作? SELECT SUM(jobRequirements.number) as total, SUM(jobRequirements.number WHER
我有 3 个 SQL 表。 游戏 wo_tenis_partidos 选择 wo_tenis_pronosticos 配额 wo_tenis_cuotas_ha2 我需要获取满足两个条件的所有行: 条
我有这张乘客表日期: 这意味着在 Reservation 000004 中,有两个行程,分别是 Itinerary 0000010 (AAC Hangar - Anvaya Cove) 和 00000
里面
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 此问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-topic在这里
我在模态框内显示一个弹出窗口,我可以在关闭时隐藏它,但在点击模态框外时无法隐藏它。我试着在关闭时隐藏它,这很好。代码在这里 $('.close, .close-button').click(funct
我所在的团队正在使用 MVC 架构开发 C# 程序。 当我完成 MVC 教程时,我有一些疑问。请帮我澄清一下这个疑惑。 1) Controller 可以对 View 进行哪些修改? 2)我认为所有 U
我正坐在一些通过#defines 生成大量代码的遗留代码上。现在我知道在 #define 中不可能有 #ifdef,但是 #if 可能吗?我想为特定类型添加一些特化。 (无需进行重大更改,例如使用模板
这是我试图用来创建触发器的代码: -- Dumping structure for trigger kavanga_lead.click_links_insert DROP TRIGGER IF EX
我想写这样的东西: #define COV_ON(x) \ #ifdef COVERAGE_TOOL \ _Pragma (CO
我在这样的定义的帮助下初始化一个结构数组: #define FLAGCODE(name) { #name, MNT_ ## name } struct { const char
我尝试将 css 和 jquery 应用于 div 元素,但它不接受 $(this) 参数。我想知道为什么我不能使用 $(this) 作为 div 元素的引用。 blabla.css({ 'top':
我是一名优秀的程序员,十分优秀!