Tag: alignment

如何垂直居中JTextPane中的文本和JComponent?

目前它看起来如此 怎么做它看起来如此? 以下是我的代码: JFrame f = new JFrame(); JTextPane textPane = new JTextPane(); JTextField component = new JTextField(” “); component.setMaximumSize(component.getPreferredSize()); textPane.setSelectionStart(textPane.getDocument().getLength()); textPane.setSelectionEnd(textPane.getDocument().getLength()); textPane.insertComponent(component); try { textPane.getDocument().insertString(textPane.getDocument().getLength(), “text”, new SimpleAttributeSet()); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } f.add(new JScrollPane(textPane)); f.setSize(200, 100); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); 我发现接近这个主题的单个问题: JTextPane插入组件,错误的垂直对齐但是如何更改对齐没有答案。 但根据那里的讨论,它必须是可能的。

如何将JMenuItem对齐更改为右对齐

我用netBeans编辑器在java中编写了一个程序。 我的表格有一个jmenuBar ,右边对齐一些jmenu 。 例如, jmenu1有一些jmenuItem ,我想要对齐所有jmenuitem的文本。 当我将它们的水平对齐方式更改为右侧时,运行时文本未显示。 menuItem1.setHorizontalAlignment(SwingConstants.RIGHT); 我怎么能这样做? http://sofzh.miximages.com/java/18431917276667197781.jpg

java – 如何使列表彼此相邻(水平)而不是向下(垂直)。

如何使列表彼此相邻(水平)而不是向下(垂直)。 例: 1月(这是我一直得到的)SMTWTFS 1 2 3 4 五 … 1月(这是我想要的)SMTWTFS 1 2 3 4 5 6 7 8 9 … 谢谢任何帮助将不胜感激,我是新来的,我无法弄清楚。 🙂

JavaFX – 以场景为中心的文本

我有一个JavaFX Text , Scene和Group Text waitingForKey Scene scene Group root 我有一个字符串String waitingForKeyString ,我正在添加到waitingForKey ,我想要一个中心对齐。 问题是,有时字符串有两个句子,我无法对齐它 String waitingForKeyString= ” Level 2 \n\n” + “Press ENTER to start a new game”; 要么 String waitingForKeyString =“按ENTER \ n”+“开始游戏”,messageString =“”; 然后 Scene scene = new Scene(root,SCREEN_WIDTH, SCREEN_HEIGHT, Color.BLACK); waitingForKey.setText(waitingForKeyString); root.getChildren().add(waitingForKey); 那我怎么能把它与中心对齐呢? 当我尝试对齐第一个waitingForKeyString我销毁了第二个`waitingForKeyString和vicecersa。

在JOptionPane中将文本右对齐

是否可以在JOptionPane中将文本对齐? (我不想使用JDialog)因为我想用阿拉伯语写一些句子

对齐JTable中单元格的值?

我不知道如何在JTable中对齐单元格的值。 对于Ex,Jtable显示,姓名薪水Mr.X 100000.50 XXXX 234.34 YYYy 1205.50 我想以下列格式对齐“工资”。 Name Salary Mr.X 100000.50 XXXX 234.34 YYYy 1205.50 如何在JTable上面对齐

Java – 将JTextArea与右对齐

我可以将JTextArea中的文本对齐到右边(或者更改文本对齐)吗? |Left | | Centered | | Right| <- Like this 我一直在寻找几个小时,似乎其他人之前已经问过这个问题,但没有好的答案(实际上有效)。 提前致谢!

BoxLayout忽略setYAlighment

这是一个function: /** * Creates an instance of a JLabel with the given arguments * @param text The text to be displayed on the Label * @param font The font of the label * @param bold set to true if you want the label’s text to be bold * @param fontSize The size of the font […]

Java:JPanel中的垂直对齐

我试图在一个JPanel中垂直对齐(居中)两个JLabel。 JPanel panel = new JPanel(); panel.setPreferredSize(size); JLabel label1 = new JLabel(icon); JLabel label2 = new JLabel(“text”); panel.add(label1); panel.add(label2); 我尝试过使用setAligmentY()但没有成功。 两个标签始终显示在JPanel的顶部。 UPD:标签应该像使用FlowLayout一样位于彼此旁边,但是在JPanel的中间。

如何在GridBagLayout单元格中左右对齐?

我看到GridBagLayout将它的子GridBagLayout定位在单元格中的中心对齐位置。 如何左右对齐? UPDATE 构造代码(我知道我可以重用c ) // button panel JPanel button_panel = new JPanel(); button_panel.add(ok_button); button_panel.add(cancel_button); // placing controls to dialog GridBagConstraints c; GridBagLayout layout = new GridBagLayout(); setLayout(layout); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; add(inputSource_label, c); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 0; add(inputSource_combo, c); c = new […]