我有一个使用JTree的java swing应用程序
我最近搬到了UHD显示器,现在JTree没有很好地扩展
我觉得它使用图标来缩放行高,但不知道如何自己影响它。
请注意,如果遗漏UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
,新显示器上的显示屏会很小
请参阅下面的截图/简单示例代码。
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTree;
import javax.swing.UIManager;
public class JTreeTest extends JFrame
{
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try {
// Set System L&F
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
JTreeTest frame = new JTreeTest();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public JTreeTest()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JTree tree = new JTree();
contentPane.add(tree, BorderLayout.CENTER);
}
}
正常分辨率jtree screenshot:
UHD决议jtree截图:
谢谢。
答案 0 :(得分:2)
也许您需要使用JTree#setRowHeight(int)
public void setRowHeight(int rowHeight)
设置每个单元格的高度(以像素为单位)。如果指定的值小于或等于零,则会为每行的高度查询当前单元格渲染器。
import java.awt.*;
import javax.swing.*;
public class JTreeTest2 extends JFrame
{
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
// Set System L&F
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
JFrame frame = new JTreeTest2();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public JTreeTest2()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JTree tree = new JTree();
tree.setFont(tree.getFont().deriveFont(32f));
JTree tree2 = new JTree();
tree2.setFont(tree2.getFont().deriveFont(32f));
tree2.setRowHeight(32);
//or: tree2.setRowHeight(0);
JPanel p = new JPanel(new GridLayout(1, 0));
p.add(new JScrollPane(tree));
p.add(new JScrollPane(tree2));
contentPane.add(p, BorderLayout.CENTER);
setBounds(100, 100, 450, 300);
}
}