List of usage examples for javax.swing SwingUtilities layoutCompoundLabel
public static String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)
From source file:Main.java
public static String layoutComponent(JComponent c, String text, Icon icon, int iconTextGap, int verticalAlignment, int horizontalAlignment, int verticalTextAlignment, int horizontalTextAlignment, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) { resetRectangles(iconRect, textRect); return SwingUtilities.layoutCompoundLabel(c, c.getFontMetrics(c.getFont()), text, icon, verticalAlignment, horizontalAlignment, verticalTextAlignment, horizontalTextAlignment, viewRect, iconRect, textRect, iconTextGap);/*from w w w.j a v a2 s. com*/ }
From source file:Main.java
public static Rectangle getTextRectangle(JLabel label) { String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if ((icon == null) && (text == null)) { return null; }// www . ja va 2 s.co m Rectangle paintIconR = new Rectangle(); Rectangle paintTextR = new Rectangle(); Rectangle paintViewR = new Rectangle(); Insets paintViewInsets = new Insets(0, 0, 0, 0); paintViewInsets = label.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; paintViewR.width = label.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.height = label.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); Graphics g = label.getGraphics(); if (g == null) { return null; } String clippedText = SwingUtilities.layoutCompoundLabel(label, g.getFontMetrics(), text, icon, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); return paintTextR; }
From source file:ExtendedTableCellRenderer.java
public void paint(Graphics g) { super.paint(g); if (underlined) { Insets i = getInsets();//from ww w .j av a2 s .c o m FontMetrics fm = g.getFontMetrics(); Rectangle textRect = new Rectangle(); Rectangle viewRect = new Rectangle(i.left, i.top, getWidth() - (i.right + i.left), getHeight() - (i.bottom + i.top)); SwingUtilities.layoutCompoundLabel(this, fm, getText(), getIcon(), getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), viewRect, new Rectangle(), textRect, getText() == null ? 0 : ((Integer) UIManager.get("Button.textIconGap")).intValue()); int offset = 2; if (UIManager.getLookAndFeel().isNativeLookAndFeel() && System.getProperty("os.name").startsWith("Windows")) { offset = 1; } g.fillRect(textRect.x + ((Integer) UIManager.get("Button.textShiftOffset")).intValue(), textRect.y + fm.getAscent() + ((Integer) UIManager.get("Button.textShiftOffset")).intValue() + offset, textRect.width, 1); } }
From source file:uiuc.dm.miningTools.ui.ParametersSelectionFrame.java
private void initComponents() throws Exception { comboOptions = new UIComboOptions(); if (!dao.isGuestMode()) { List<String> datasetNames = dao.getDatasetNames(); // create inputs fields datasetCombo = new JComboBox(datasetNames.toArray(new String[datasetNames.size()])); datasetCombo// w w w . j a va 2s.c om .setPrototypeDisplayValue("White-faced capuchin, ARTS Crofoot Barro Colorado Island, Panama"); datasetCombo.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (index == -1) { datasetCombo.setToolTipText(value.toString()); return this; } setToolTipText(value.toString()); Rectangle textRect = new Rectangle(datasetCombo.getSize().width, getPreferredSize().height); String shortText = SwingUtilities.layoutCompoundLabel(this, getFontMetrics(getFont()), value.toString(), null, getVerticalAlignment(), getHorizontalAlignment(), getHorizontalTextPosition(), getVerticalTextPosition(), textRect, new Rectangle(), textRect, getIconTextGap()); setText(shortText); return this; } }); AutoCompleteDecorator.decorate(datasetCombo); datasetLabel = new JLabel("Dataset: "); } /*Fei*/ this.dMaxThresLabel = new JLabel("Dist thres(meters): "); this.lMaxThresLabel = new JLabel("Time thres(seconds): "); this.minIntervalLengthLabel = new JLabel("Min Interval Length(seconds): "); this.dMaxLabelTextedField = new JTextField(5); this.lMaxLabelTextedField = new JTextField(5); this.minIntervalLengthField = new JTextField(5); /**/ functionCombo = new JComboBox(comboOptions.getFunctionOptions()); displayMethodCombo = new JComboBox(comboOptions.getDvOption()); gapCombo = new JComboBox(comboOptions.getGapOption()); thresGapCombo = new JComboBox(comboOptions.getThresGapOption()); numRoundCombo = new JComboBox(comboOptions.getNumRoundOption()); functionLabel = new JLabel("Mining function: "); dvLabel = new JLabel("Display method: "); gapLabel = new JLabel("Gap(min): "); thresGapLabel = new JLabel("ThresGap(hr): "); numRoundLabel = new JLabel("# Rounds: "); instructionLabel = new JLabel("Please select a dataset and some parameters"); distThresLabel = new JLabel("Dist thres(meters): "); this.interpLabel = new JLabel("Interpolate: "); distThresTextedField = new JTextField(5); downloadDatasetProgressBar = new JProgressBar(0, 100); downloadDatasetProgressBar.setValue(0); downloadDatasetProgressBar.setStringPainted(true); dataInterpolationHelpButton = new JButton("?"); miningFucntionHelpButton = new JButton("?"); miningFucntionParamsHelpButton = new JButton("?"); this.miningFunctionParamsHelpButtonFollowing = new JButton("?"); selectIndividualsButton = new JButton("Select individuals"); selectIndividualsButton.addActionListener(this); saveKmlButton = new JButton("Get KML file"); saveKmlButton.addActionListener(this); saveDensityMapButton = new JButton("Get density map"); saveDensityMapButton.addActionListener(this); }