Refine search
return getPreferredSize().width < getParent().getWidth(); getContentPane().add( scrollPane ); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setSize(400, 300); frame.setVisible(true);
/** * 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的JTableHeader 的大小 * 通过Renderer取得组件 * * @return */ public Dimension getSize(JTable table) { Component comp = renderer.getTableCellRendererComponent(table, getHeaderValue(), false, false, -1, -1); int height = comp.getPreferredSize().height; int width = 0; // 宽度需要计算合并的还要加上间隙 Enumeration<Object> enumeration = vector.elements(); while (enumeration.hasMoreElements()) { Object obj = enumeration.nextElement(); if (obj instanceof TableColumn) { TableColumn aColumn = (TableColumn) obj; width += aColumn.getWidth(); width += margin; } else { width += ((ColumnGroup) obj).getSize(table).width; } } return new Dimension(width, height); }
component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB ); component.paint( image.getGraphics() ); // alternately use .printAll(..) return image; Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); public void actionPerformed(ActionEvent ae) { BufferedImage img = getScreenShot( f.getContentPane() ); JOptionPane.showMessageDialog( null, JMenuBar mb = new JMenuBar(); mb.add(menu); f.setJMenuBar(mb); p.setBorder( new TitledBorder("Main GUI") ); p.add( new JScrollPane(new JTree()), BorderLayout.WEST ); p.add( new JScrollPane( new JTextArea(HELP,10,30) ), BorderLayout.CENTER );
protected void minimumSizeDialog(Component component, int minWidth, int minHeight) { // set the min width if (component.getSize().width < minWidth) component.setSize(minWidth, component.getSize().height); // set the min height if (component.getSize().height < minHeight) component.setSize(component.getSize().width, minHeight); } //--------------------------------------------------------------------------
private int getHeight(@Nullable Component nodeComp) { if (nodeComp != null) { return Math.max(nodeComp.getHeight(), nodeComp.getPreferredSize().height); } return 0; } }
autoSuggestionPopUpWindow.requestFocusInWindow(); suggestionsPanel.requestFocusInWindow(); suggestionsPanel.getComponent(i).requestFocusInWindow(); break; autoSuggestionPopUpWindow.requestFocusInWindow(); suggestionsPanel.requestFocusInWindow(); suggestionsPanel.getComponent(i).requestFocusInWindow(); lastFocusableIndex = i; break; container.requestFocusInWindow(); if (autoSuggestionPopUpWindow.isVisible()) { windowX = container.getX() + textField.getX() + 5; if (suggestionsPanel.getHeight() > autoSuggestionPopUpWindow.getMinimumSize().height) { windowY = container.getY() + textField.getY() + textField.getHeight() + autoSuggestionPopUpWindow.getMinimumSize().height; } else { windowY = container.getY() + textField.getY() + textField.getHeight() + autoSuggestionPopUpWindow.getHeight(); autoSuggestionPopUpWindow.setMinimumSize(new Dimension(textField.getWidth(), 30)); autoSuggestionPopUpWindow.revalidate(); autoSuggestionPopUpWindow.repaint(); setFocusable(true); addMouseListener(new MouseAdapter() { @Override
import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class Test { public static void main(String... args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); for (int i = 0; i < 10; i++) { panel.add(new JButton("Hello-" + i)); } JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollPane.setBounds(50, 30, 300, 50); JPanel contentPane = new JPanel(null); contentPane.setPreferredSize(new Dimension(500, 400)); contentPane.add(scrollPane); frame.setContentPane(contentPane); frame.pack(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setVisible(true); } }
private JFrame frame = new JFrame("sssssssss"); private JButton tip1Null = new JButton(" test button "); final Border compound2; compound2 = BorderFactory.createCompoundBorder(empty, new OldRoundedBorderLine(crl2)); tip1Null.setFont(new Font("Serif", Font.BOLD, 14)); tip1Null.setForeground(Color.darkGray); tip1Null.setPreferredSize(new Dimension(50, 30)); tip1Null.addActionListener(new java.awt.event.ActionListener() { @Override frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tip1Null, BorderLayout.CENTER); frame.setLocation(150, 150); frame.setPreferredSize(new Dimension(310, 75)); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); paintText(g, b, b.getBounds(), b.getText()); g.setColor(Color.red.brighter()); g.fillRect(0, 0, b.getSize().width, b.getSize().height);
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gui.setBorder( new TitledBorder("BorderLayout(5,5)") ); plafComponents.add(plafChooser); plafComponents.add(pack); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); gui.add( splitPane, BorderLayout.CENTER ); frame.setContentPane(gui); frame.pack(); frame.setLocationRelativeTo(null); frame.setLocationByPlatform(true); frame.setMinimumSize(frame.getSize()); } catch(Throwable ignoreAndContinue) {
JFrame f = new JFrame("AnimationTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); timer.start(); this.setOpaque(false); this.setPreferredSize(new Dimension(WIDE, HIGH)); this.addMouseListener(new MouseHandler()); this.addComponentListener(new ComponentHandler()); long start = System.nanoTime(); super.paintComponent(g); int w = this.getWidth(); int h = this.getHeight(); g.drawImage(background, 0, 0, this); this.repaint(); JTextField field = new JTextField("test"); Dimension d = field.getPreferredSize(); field.setBounds(e.getX(), e.getY(), d.width, d.height); add(field);
addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent event) { JScrollBar scrollBar = getScrollBar(); popupScrollBar.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { doLayout(); repaint(); if(scrollBar.isVisible()){ int extent = 0; int max = 0; Dimension preferredSize = comp.getPreferredSize(); width = Math.max(width, preferredSize.width); if(unit < 0){ Dimension dim = new Dimension(); for(Component comp :parent.getComponents()){ if(comp.isVisible()) { if(comp instanceof JScrollBar){ JScrollBar scrollBar = (JScrollBar) comp; Dimension pref = comp.getPreferredSize(); dim.width = Math.max(dim.width, pref.width); dim.height += pref.height; Dimension dim = new Dimension(); for(Component comp : parent.getComponents()) {
JFrame f = new JFrame("LowerRightFrame"); f.add(new JPanel() { return new Dimension(320, 240); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight(); f.setLocation(x, y); f.setVisible(true);
JFrame frame = new JFrame(); JPanel panel = new JPanel(); JLabel label = new JLabel("Loading..."); int max = 1000; jpb.setMaximum(max); panel.add(label); panel.add(jpb); frame.add(panel); frame.pack(); frame.setSize(200,90); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new Task_IntegerUpdate(jpb, max, label).execute(); try { get(); JOptionPane.showMessageDialog(jpb.getParent(), "Success", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ExecutionException | InterruptedException e) { e.printStackTrace();
setBorder(new LineBorder(Color.BLUE, 3)); setBackground(Color.WHITE); setBounds(0, 0, 100, 100); setOpaque(false); addMouseListener(new MouseListener() { addMouseMotionListener(new MouseMotionListener() { int deltaY = e.getYOnScreen() - screenY; setLocation(myX + deltaX, myY + deltaY); JFrame f = new JFrame("Swing Hello World"); f.setLayout(null); f.add(mc); f.setSize(500, 500); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setVisible(true);
import java.awt.*; import javax.swing.*; class FixedSizeContent { public static void main(String[] args) { SwingUtilities.invokeLater( new Runnable() { public void run() { JFrame f = new JFrame("Fixed size content"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container c = f.getContentPane(); c.setBackground(Color.YELLOW); // adjust to need. Dimension d = new Dimension(400,40); c.setPreferredSize(d); f.pack(); f.setResizable(false); f.setVisible(true); } }); } }
box.setAlignmentX(JComponent.CENTER_ALIGNMENT); box.add(Box.createVerticalGlue()); box.add(new CustomComponents12()); box.add(Box.createVerticalGlue()); add(box); pack(); setTitle("Custom Component Test / BoxLayout"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setMaximumSize(getMinimumSize()); setMinimumSize(getMinimumSize()); setPreferredSize(getPreferredSize()); setLocation(150, 150); setVisible(true); return new Dimension(100, 100); return new Dimension(100, 100); return new Dimension(100, 100); public void paintComponent(Graphics g) { int margin = 10; Dimension dim = getSize(); super.paintComponent(g); g.setColor(Color.red);
synchronized (target.getTreeLock()) { int hgap = getHgap(); int vgap = getVgap(); int w = target.getWidth(); Component c = target.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); if ((x == 0) || ((x + d.width) <= maxwidth)) { return new Dimension(reqdWidth+insets.left+insets.right, y); synchronized (target.getTreeLock()) { int minx = Integer.MAX_VALUE; int miny = Integer.MIN_VALUE; Component c = target.getComponent(i); if (c.isVisible()) { found_one = true; Dimension d = c.getPreferredSize(); minx = Math.min(minx, d.width); miny = Math.min(miny, d.height); return new Dimension(minx, miny); return new Dimension(0, 0);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Insets scnMax = Toolkit.getDefaultToolkit(). getScreenInsets(dialog.getGraphicsConfiguration()); int taskBarSize = scnMax.bottom; panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; dialog.dispose(); b.setOpaque(false); b.setMargin(new Insets(1, 4, 1, 4)); b.setFocusable(false); panel.add(b, constraints); dialog.setUndecorated(true); dialog.setSize(300, 100); dialog.setLocation(screenSize.width - dialog.getWidth(), screenSize.height - taskBarSize - dialog.getHeight()); lpg = new LinearGradientPaint(0, 0, 0, dialog.getHeight() / 2, new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f), new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)}); setOpaque(true);
this.setSize(300, 200); this.setContentPane(getJContentPane()); this.setTitle("JFrame"); if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(null); panel.setBounds(61, 11, 81, 140); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); jContentPane.add(panel); frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);