久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='I4Nxa'><style id='I4Nxa'><dir id='I4Nxa'><q id='I4Nxa'></q></dir></style></legend>

      <bdo id='I4Nxa'></bdo><ul id='I4Nxa'></ul>

      <small id='I4Nxa'></small><noframes id='I4Nxa'>

      <i id='I4Nxa'><tr id='I4Nxa'><dt id='I4Nxa'><q id='I4Nxa'><span id='I4Nxa'><b id='I4Nxa'><form id='I4Nxa'><ins id='I4Nxa'></ins><ul id='I4Nxa'></ul><sub id='I4Nxa'></sub></form><legend id='I4Nxa'></legend><bdo id='I4Nxa'><pre id='I4Nxa'><center id='I4Nxa'></center></pre></bdo></b><th id='I4Nxa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='I4Nxa'><tfoot id='I4Nxa'></tfoot><dl id='I4Nxa'><fieldset id='I4Nxa'></fieldset></dl></div>

      <tfoot id='I4Nxa'></tfoot>

      如何在 jTextArea(或其他類(lèi)型的控制臺(tái))中保留命令

      How to preserve command prompt#39;s formatting inside a jTextArea (or some other type of console)?(如何在 jTextArea(或其他類(lèi)型的控制臺(tái))中保留命令提示符的格式?)
      • <legend id='cGgdV'><style id='cGgdV'><dir id='cGgdV'><q id='cGgdV'></q></dir></style></legend>

        1. <small id='cGgdV'></small><noframes id='cGgdV'>

            <bdo id='cGgdV'></bdo><ul id='cGgdV'></ul>

              <tfoot id='cGgdV'></tfoot>

                <tbody id='cGgdV'></tbody>

              • <i id='cGgdV'><tr id='cGgdV'><dt id='cGgdV'><q id='cGgdV'><span id='cGgdV'><b id='cGgdV'><form id='cGgdV'><ins id='cGgdV'></ins><ul id='cGgdV'></ul><sub id='cGgdV'></sub></form><legend id='cGgdV'></legend><bdo id='cGgdV'><pre id='cGgdV'><center id='cGgdV'></center></pre></bdo></b><th id='cGgdV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='cGgdV'><tfoot id='cGgdV'></tfoot><dl id='cGgdV'><fieldset id='cGgdV'></fieldset></dl></div>
                本文介紹了如何在 jTextArea(或其他類(lèi)型的控制臺(tái))中保留命令提示符的格式?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                當(dāng)我在 Java 程序中輸出流時(shí),我無(wú)法弄清楚如何保留命令提示符的格式.有人有什么建議嗎?

                I cannot figure out how to preserve command prompt's formatting when I output the stream inside a Java program. Anyone have any suggestions?

                推薦答案

                根據(jù)數(shù)據(jù)的派生方式,您可以使用多種可能的解決方案...

                There are a number of possible solutions available to you depending on how your data is derived...

                最基本的方法是確保您使用的是固定寬度的字體...

                The most basic would be to ensure you are using a fixed width font...

                import java.awt.BorderLayout;
                import java.awt.EventQueue;
                import javax.swing.JFrame;
                import javax.swing.JPanel;
                import javax.swing.JScrollPane;
                import javax.swing.JTextArea;
                import javax.swing.UIManager;
                import javax.swing.UnsupportedLookAndFeelException;
                
                public class OutputTest {
                
                    public static void main(String[] args) {
                        new OutputTest();
                    }
                
                    public OutputTest() {
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                    ex.printStackTrace();
                                }
                
                                JFrame frame = new JFrame("Testing");
                                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                frame.add(new TestPane());
                                frame.pack();
                                frame.setLocationRelativeTo(null);
                                frame.setVisible(true);
                            }
                        });
                    }
                
                    public class TestPane extends JPanel {
                
                        public TestPane() {
                            String[] lines = {
                                "Idx     Met        MTU        State                Name           ",
                                "---  ---------  ----------  ------------  --------------------------",
                                "  1         50  4294967295  connected     Loopback Psudo-Interface 1",
                                " 11         10        1500  connected     Local Area Connection     ",
                                " 11          5        1500  disconnected  Local Area Connection 3   ",
                            };
                
                            setLayout(new BorderLayout());
                            JTextArea ta = new JTextArea(10, 40);
                            ta.setFont(new Font("Monospaced", Font.PLAIN, 13));
                            for (String text : lines) {
                                ta.append(text + "
                ");
                            }
                            add(new JScrollPane(ta));
                        }
                
                    }
                
                }
                

                如果您的管道內(nèi)容來(lái)自其他來(lái)源(如外部命令),那就太好了.

                This is great if your piping content from another source (like an external command).

                如果您可以控制內(nèi)容,則可以使用 String.format,但同樣,除非您使用固定寬度的字體,否則不會(huì)有任何區(qū)別,您仍然可以格式問(wèn)題.

                If you have control of the content, you could use String.format, but again, unless you're using a fixed width font, it won't make any difference, you will still have formatting issues.

                另一種解決方案是在 JEditorPane 中使用 html 表格,然后字體無(wú)關(guān)緊要

                Another solution would be to use a html table in a JEditorPane, then the font doesn't matter

                另一種解決方案可能是使用 JTable,它旨在以表格形式呈現(xiàn)數(shù)據(jù).有關(guān)詳細(xì)信息,請(qǐng)參閱如何使用表

                Another solution might be to use a JTable which is designed to present data in a tabular form. See How to Use Tables for more details

                更新

                我很確定這是 Netbeans 8.0 中自動(dòng)生成的代碼的一個(gè)錯(cuò)誤.只是讓追查問(wèn)題變得很困難.

                It's a bug with the auto generated code in Netbeans 8.0 I'm pretty sure. It just made it tough to track down the issue.

                我非常懷疑這是一個(gè)錯(cuò)誤,因?yàn)槊刻於加袛?shù)百人(甚至數(shù)千人)使用它......但沒(méi)有 可運(yùn)行的示例,它展示了您無(wú)法確定的問(wèn)題...

                I doubt very highly that it's a bug, as this is been used by hundreds if not thousands of people every day...but without a runnable example which demonstrates your problem it's impossible to know for sure...

                ta.setFont(new Font("Monospaced", Font.PLAIN, 13));但是,如果您切換到粗體或斜體或粗斜體,則會(huì)生成該行并正常工作.

                ta.setFont(new Font("Monospaced", Font.PLAIN, 13)); BUT if you switch to bold or italics or bold italics then the line is generated and works correctly.

                我不同意...

                import java.awt.BorderLayout;
                import java.awt.Dimension;
                import java.awt.EventQueue;
                import java.awt.Font;
                import java.awt.GridLayout;
                import javax.swing.JFrame;
                import javax.swing.JPanel;
                import javax.swing.JScrollPane;
                import javax.swing.JTextArea;
                import javax.swing.UIManager;
                import javax.swing.UnsupportedLookAndFeelException;
                
                public class TestTable {
                
                    public static void main(String[] args) {
                        new TestTable();
                    }
                
                    public TestTable() {
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                    ex.printStackTrace();
                                }
                
                                JFrame frame = new JFrame("Testing");
                                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                frame.add(new TestPane());
                                frame.pack();
                                frame.setLocationRelativeTo(null);
                                frame.setVisible(true);
                            }
                        });
                    }
                
                    public class TestPane extends JPanel {
                
                        public TestPane() {
                            setLayout(new GridLayout(4, -1));
                            String[] lines = {
                                "Idx     Met        MTU        State                Name           ",
                                "---  ---------  ----------  ------------  --------------------------",
                                "  1         50  4294967295  connected     Loopback Psudo-Interface 1",
                                " 11         10        1500  connected     Local Area Connection     ",
                                " 11          5        1500  disconnected  Local Area Connection 3   ",};
                
                            Font baseFont = new Font("Monospaced", Font.PLAIN, 13);
                            addTextArea(baseFont, lines);
                            addTextArea(baseFont.deriveFont(Font.ITALIC), lines);
                            addTextArea(baseFont.deriveFont(Font.BOLD), lines);
                            addTextArea(baseFont.deriveFont(Font.BOLD | Font.ITALIC), lines);
                        }
                
                        protected void addTextArea(Font font, String... lines) {
                
                            JTextArea ta = new JTextArea(20, 40);
                            ta.setFont(font);
                            for (String text : lines) {
                                ta.append(text + "
                ");
                            }
                            ta.setCaretPosition(0);
                            add(new JScrollPane(ta));
                        }
                
                        @Override
                        public Dimension getPreferredSize() {
                            return new Dimension(200, 200);
                        }
                
                    }
                }
                

                這篇關(guān)于如何在 jTextArea(或其他類(lèi)型的控制臺(tái))中保留命令提示符的格式?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)

                  • <bdo id='RJKAh'></bdo><ul id='RJKAh'></ul>

                    <small id='RJKAh'></small><noframes id='RJKAh'>

                    • <legend id='RJKAh'><style id='RJKAh'><dir id='RJKAh'><q id='RJKAh'></q></dir></style></legend>
                      <tfoot id='RJKAh'></tfoot>
                    • <i id='RJKAh'><tr id='RJKAh'><dt id='RJKAh'><q id='RJKAh'><span id='RJKAh'><b id='RJKAh'><form id='RJKAh'><ins id='RJKAh'></ins><ul id='RJKAh'></ul><sub id='RJKAh'></sub></form><legend id='RJKAh'></legend><bdo id='RJKAh'><pre id='RJKAh'><center id='RJKAh'></center></pre></bdo></b><th id='RJKAh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RJKAh'><tfoot id='RJKAh'></tfoot><dl id='RJKAh'><fieldset id='RJKAh'></fieldset></dl></div>
                        <tbody id='RJKAh'></tbody>

                          主站蜘蛛池模板: 欧美精品一区二区三区在线 | 国产精品久久久久9999鸭 | 亚洲国产欧美在线 | 国产乱码精品一区二区三区忘忧草 | 久久久91 | 亚洲精品欧美精品 | 久久99这里只有精品 | 久久久久久久久久久91 | 日本特黄a级高清免费大片 特黄色一级毛片 | 91秦先生艺校小琴 | 国产成人综合一区二区三区 | 午夜激情免费 | 欧美成人一级 | 91五月婷蜜桃综合 | 久久国产精品免费 | 三级在线视频 | 色狠狠桃花综合 | 国产片淫级awww | 国产亚洲精品精品国产亚洲综合 | 国产精品视频免费观看 | 久久伊人亚洲 | 黑人巨大精品欧美一区二区免费 | 伊人精品在线视频 | 天堂视频中文在线 | 久久久久国产一区二区三区四区 | 久久69精品久久久久久久电影好 | 成人三级在线观看 | 久草.com | 欧美区日韩区 | 五月天国产 | 美女一区| 久久久高清 | 天天在线操 | 日韩在线观看网站 | 国产一区二区久久 | 欧美精品一区二区三区蜜桃视频 | 精品亚洲一区二区三区四区五区 | 亚洲成人高清 | 97人人超碰 | 欧美国产日韩在线观看 | 亚洲一二三区精品 |