我正在使用 Swing 应用程序。我在分辨率(1280 * 1024)中构建了许多表格。当我以分辨率部署应用程序时,表单会以分辨率 (1024*768) 和其他较小的分辨率进行裁剪。我已经尝试过MIGLayOutManager!和GridBagLayout!因为如果您从头开始开发应用程序,这些是更可取的,但它们对我不起作用。我想使用 示例调整框架的子控件的大小!
下面是我在@Guillaume Polet 的 Answer 编辑中用于GridBagLayOut的代码
try {
Utility util = new Utility(null);
Component[] com = null;
java.util.List<Component> jComp = new ArrayList<Component>();
if (obj instanceof JPanel) {
JPanel panel = (JPanel) obj;
com = panel.getComponents();
} else if (obj instanceof JFrame) {
JFrame JFrm = (JFrame) obj;
jComp = util.harvestAllComp(JFrm);
} else if (obj instanceof JFrame) {
JFrame frm = (JFrame) obj;
// frm.cp = cp;
String dbName = "GoldNew";
util = new Utility(dbName);
DBEngine db = new DBEngine(dbName);
for (int a = 0; a < jComp.size(); a++) {
if (jComp.get(a) instanceof JLabel) {
JLabel label = (JLabel) com[a];
} else if (jComp.get(a) instanceof JTextField) {
JTextField jtxt = (JTextField) jComp.get(a);
jtxt.setEditable(boolEnable);
// Do Nothing
} else if (jComp.get(a) instanceof JTextArea) {
JTextArea jtxt = (JTextArea) jComp.get(a);
jtxt.setEditable(boolEnable);
} else if (jComp.get(a) instanceof JXDatePicker) {
JXDatePicker jdate = (JXDatePicker) jComp.get(a);
jdate.setEditable(boolEnable);
jdate.getEditor().setEditable(false);
// Do Nothing
} else if (jComp.get(a) instanceof JTabbedPane) {
JTabbedPane tabPane = (JTabbedPane) jComp.get(a);
Component[] comTab = tabPane.getComponents();
tabPane.removeAll();
GridBagLayout tabLayOut = new GridBagLayout();
tabPane.setLayout(tabLayOut);
addRowOfComponents(tabPane, comTab);
}
if (jComp.get(a) instanceof JPanel) {
JPanel panel2 = (JPanel) jComp.get(a);
Component[] comTab = panel2.getComponents();
panel2.removeAll();
GridBagLayout tabLayOut = new GridBagLayout();
panel2.setLayout(tabLayOut);
addRowOfComponents(panel2, comTab);
} else if (jComp.get(a) instanceof JTable) {
final JTable tbl = (JTable) jComp.get(a);
tbl.getTableHeader().setReorderingAllowed(false);
} else if ((!(jComp.get(a) instanceof JTextField)) && (!(jComp.get(a) instanceof JXDatePicker))
&& (!(jComp.get(a) instanceof JTextArea))
&& (!(jComp.get(a) instanceof JLabel))) {
// jComp.get(a).setEnabled(boolEnable);
jComp.get(a).setEnabled(boolEnable);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
我想使用组件大小和屏幕大小来确定纵横比和使用纵横比缩放组件,如示例中所示!使用以下信息。如果有人指导如何完成任务,我将非常感激。
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frm.setBounds(0, 0, dim.width - 100, dim.height - 100);
int w = frm.getSize().width;//Size Of Form
int h = frm.getSize().height;
int x = (dim.width - w) / 2;
int y = (dim.height - h) / 2;