下面列出了怎么用javax.swing.JComponent的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void valueChanged(long bid)
{
boolean bHasVisible = false;
for (final JComponent comp : components) {
if (comp.isShowing()) {
bHasVisible = true;
break;
}
}
lastBID = bid;
if (bHasVisible) {
valueChangedLazy(bid);
}
}
/**
* {@inheritDoc}
*/
@Override
public void mouseMoved(MouseEvent e) {
currentMouseX = e.getX();
currentMouseY = e.getY();
Cursor cursorToUse = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
if (isOverCancelButton() || isOverFindButton()) {
cursorToUse = Cursor.getDefaultCursor();
}
JComponent c = (JComponent) e.getSource();
if (!cursorToUse.equals(c.getCursor())) {
c.setCursor(cursorToUse);
}
super.mouseMoved(e);
}
@RandomlyFails // NB-Core-Build #1176
public void testCustomComponentIsInitialized() {
Controller.defaultInstance = new TestController();
ProgressHandle handle = ProgressHandleFactory.createHandle("task 1");
// Warning, this will make the handle to work with a new Controller, not TestController.
JComponent component = ProgressHandleFactory.createProgressComponent(handle);
handle.start(15);
handle.progress(2);
waitForTimerFinish();
assertEquals(15, ((JProgressBar) component).getMaximum());
assertEquals(2, ((JProgressBar) component).getValue());
handle = ProgressHandleFactory.createHandle("task 2");
component = ProgressHandleFactory.createProgressComponent(handle);
handle.start(20);
waitForTimerFinish();
assertEquals(20, ((JProgressBar) component).getMaximum());
assertEquals(0, ((JProgressBar) component).getValue());
}
@NbBundle.Messages({
"LAB_ToolsActionInitializing=Initializing..."
})
@Override
public JComponent[] synchMenuPresenters(JComponent[] items) {
G g = gl(50);
if (g == null) {
JMenuItem init = new JMenuItem();
init.setText(Bundle.LAB_ToolsActionInitializing());
init.setEnabled(false);
return new JMenuItem[] { init };
}
if (timestamp == g.getTimestamp()) {
return items;
}
// generate directly list of menu items
List<JMenuItem> l = generate(toolsAction, true);
timestamp = gl().getTimestamp();
return l.toArray(new JMenuItem[l.size()]);
}
private void assertStacked(DockingWindowManager dwm, ComponentProvider... providers) {
Integer x = null;
Integer y = null;
for (ComponentProvider p : providers) {
ComponentPlaceholder ph = dwm.getActivePlaceholder(p);
ComponentNode n = ph.getNode();
JComponent c = n.getComponent();
Point l = c.getLocationOnScreen();
if (x == null) {
x = l.x;
y = l.y;
}
else {
assertEquals("Providers are not stacked together", x.intValue(), l.x);
assertEquals("Providers are not stacked together", y.intValue(), l.y);
}
}
}
public MostradorDeCodigo(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
lblHtml = new JLabel();
scrPrincipal.getViewport().add(lblHtml);
//dbModel.InicieAnsi2011();
getRootPane().registerKeyboardAction(e -> {
//this.dispose();
//setResultado(JOptionPane.CANCEL_OPTION);
setVisible(false);
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
getRootPane().registerKeyboardAction(e -> {
//setResultado(JOptionPane.OK_OPTION);
setVisible(false);
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, java.awt.event.InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
getRootPane().registerKeyboardAction(e -> {
btnCopyActionPerformed(null);
}, KeyStroke.getKeyStroke(KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_DOWN_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
setTitle(Editor.fromConfiguracao.getValor("Controler.interface.Titulo.MostradorDeCodigo"));
this.pack();
}
@Override
public int getSourceActions(JComponent c) {
DisplayableCard p = (DisplayableCard) c;
Point pt = p.getLocation();
SwingUtilities.convertPointToScreen(pt, p);
dragLab.setIcon(p.toIcon());
window.setLocation(pt);
return MOVE;
}
/**
* Verifies the input with the side effect that the background color of {@code input} to {@code background} if
* returns {@code true}, or {@code warningBackground} otherwise
*
* @param input component
* @return if input is valid
*/
public boolean shouldYieldFocus(JComponent input) {
boolean isValidInput = verify(input);
if (isValidInput) {
input.setBackground(background);
} else {
input.setBackground(warningBackground);
}
return isValidInput;
}
/**
* Invokes the <code>getAccessibleChildrenCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getAccessibleChildrenCount(JComponent a) {
int returnValue =
((ComponentUI) (uis.elementAt(0))).getAccessibleChildrenCount(a);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).getAccessibleChildrenCount(a);
}
return returnValue;
}
@SuppressWarnings("deprecation")
public Component prepareEditor(TableCellEditor editor, int index) {
Object value = columnModel.getColumn(index).getHeaderValue();
boolean isSelected = true;
int row = HEADER_ROW;
JTable table = getTable();
Component comp = editor.getTableCellEditorComponent(table, value, isSelected, row, index);
if (comp instanceof JComponent) {
((JComponent) comp).setNextFocusableComponent(this);
}
return comp;
}
protected JComponent makeMainVisualizationComponent(Example example) {
JComponent main;
String[] columnNames = new String[] { "Attribute", "Value" };
String[][] data = new String[exampleSet.getAttributes().allSize()][2];
Iterator<Attribute> a = exampleSet.getAttributes().allAttributes();
int counter = 0;
while (a.hasNext()) {
Attribute attribute = a.next();
data[counter][0] = attribute.getName();
data[counter][1] = getFormattedValue(example, attribute);
counter++;
}
ExtendedJTable table = new ExtendedJTable();
table.setDefaultEditor(Object.class, null);
TableModel tableModel = new DefaultTableModel(data, columnNames);
table.setRowHighlighting(true);
table.setRowHeight(PropertyPanel.VALUE_CELL_EDITOR_HEIGHT);
table.setModel(tableModel);
main = new ExtendedJScrollPane(table);
main.setBorder(null);
int tableHeight = (int) (table.getPreferredSize().getHeight() + table.getTableHeader().getPreferredSize().getHeight()
+ 5); // 5 for border
if (tableHeight < main.getPreferredSize().getHeight()) {
main.setPreferredSize(new Dimension((int) main.getPreferredSize().getWidth(), tableHeight));
}
return main;
}
/**
* Invokes the <code>getAccessibleChild</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Accessible getAccessibleChild(JComponent a, int b) {
Accessible returnValue =
((ComponentUI) (uis.elementAt(0))).getAccessibleChild(a,b);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).getAccessibleChild(a,b);
}
return returnValue;
}
private static void invalidateAndRepaint(Container container) {
if (container == null) {
return;
}
if (container instanceof JComponent) {
((JComponent) container).revalidate();
} else {
container.invalidate();
}
container.repaint();
}
/**
* Returns a multiplexing UI instance if any of the auxiliary
* <code>LookAndFeel</code>s supports this UI. Otherwise, just returns the
* UI object obtained from the default <code>LookAndFeel</code>.
*/
public static ComponentUI createUI(JComponent a) {
ComponentUI mui = new MultiProgressBarUI();
return MultiLookAndFeel.createUIs(mui,
((MultiProgressBarUI) mui).uis,
a);
}
@Override
public JComponent getComponent(Lookup masterLookup) {
if (panel == null) {
panel = new OnSaveTabPanel();
}
return panel;
}
/**
* Invokes the <code>contains</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public boolean contains(JComponent a, int b, int c) {
boolean returnValue =
((ComponentUI) (uis.elementAt(0))).contains(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).contains(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>contains</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public boolean contains(JComponent a, int b, int c) {
boolean returnValue =
uis.elementAt(0).contains(a,b,c);
for (int i = 1; i < uis.size(); i++) {
uis.elementAt(i).contains(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>getAccessibleChildrenCount</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getAccessibleChildrenCount(JComponent a) {
int returnValue =
((ComponentUI) (uis.elementAt(0))).getAccessibleChildrenCount(a);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).getAccessibleChildrenCount(a);
}
return returnValue;
}
/**
* Invokes the <code>getMinimumSize</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Dimension getMinimumSize(JComponent a) {
Dimension returnValue =
((ComponentUI) (uis.elementAt(0))).getMinimumSize(a);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).getMinimumSize(a);
}
return returnValue;
}
public ChooseKnowledgeAction(WorldObject playerCharacter, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, World world, JComponent parent, ActionContainingArgs guiAction, JFrame parentFrame) {
super();
this.playerCharacter = playerCharacter;
this.imageInfoReader = imageInfoReader;
this.soundIdReader = soundIdReader;
this.world = world;
this.parent = parent;
this.guiAction = guiAction;
this.parentFrame = parentFrame;
}
/**
* Invokes the <code>getMinimumSize</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Dimension getMinimumSize(JComponent a) {
Dimension returnValue =
uis.elementAt(0).getMinimumSize(a);
for (int i = 1; i < uis.size(); i++) {
uis.elementAt(i).getMinimumSize(a);
}
return returnValue;
}
SlidingSpinner(ColorPanel panel, JComponent label) {
this.panel = panel;
this.label = label;
this.slider.addChangeListener(this);
this.spinner.addChangeListener(this);
DefaultEditor editor = (DefaultEditor) this.spinner.getEditor();
ValueFormatter.init(3, false, editor.getTextField());
editor.setFocusable(false);
this.spinner.setFocusable(false);
}
/**
* Returns a multiplexing UI instance if any of the auxiliary
* <code>LookAndFeel</code>s supports this UI. Otherwise, just returns the
* UI object obtained from the default <code>LookAndFeel</code>.
*/
public static ComponentUI createUI(JComponent a) {
ComponentUI mui = new MultiTableUI();
return MultiLookAndFeel.createUIs(mui,
((MultiTableUI) mui).uis,
a);
}
/**
* Invokes the <code>getMinimumSize</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Dimension getMinimumSize(JComponent a) {
Dimension returnValue =
((ComponentUI) (uis.elementAt(0))).getMinimumSize(a);
for (int i = 1; i < uis.size(); i++) {
((ComponentUI) (uis.elementAt(i))).getMinimumSize(a);
}
return returnValue;
}
public JComponent createComponent(Category category, Lookup context) {
Project project = context.lookup(Project.class);
ProjectAccessor acc = context.lookup(ProjectAccessor.class);
AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class);
assert aux != null;
assert acc != null;
assert project != null;
final JdkConfiguration jdkConf = new JdkConfiguration(project, acc.getHelper(), acc.getEvaluator());
final ClasspathPanel panel = new ClasspathPanel(jdkConf);
final JavaPlatform initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem();
ProjectModel pm = context.lookup(ProjectModel.class);
assert pm != null;
panel.setModel(pm);
pm.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent arg0) {
panel.updateControls();
}
});
category.setOkButtonListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem();
if (p != initialPlatform) {
try {
jdkConf.setSelectedPlatform(p);
} catch (IOException x) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x);
}
}
}
});
return panel;
}
/**
* Returns a multiplexing UI instance if any of the auxiliary
* <code>LookAndFeel</code>s supports this UI. Otherwise, just returns the
* UI object obtained from the default <code>LookAndFeel</code>.
*/
public static ComponentUI createUI(JComponent a) {
ComponentUI mui = new MultiFileChooserUI();
return MultiLookAndFeel.createUIs(mui,
((MultiFileChooserUI) mui).uis,
a);
}
/**
* @param pf Portfolio which is dynamically evaluated at mouse-even-time for
* any contained private companies
*/
public static void addMouseListener(JComponent c,ORUIManager orUIManager,PortfolioModel pf) {
if (isEnabled(false)) {
HexHighlightMouseListener l = new HexHighlightMouseListener(orUIManager);
l.portfolio = pf;
c.addMouseListener(l);
}
}
/**
* Used to get the JComponent used for the structure pane. Usually a container for the structure component or the structure component itself.
* @return the JComponent
*/
public JComponent getStructureView(){
if (structureView ==null){
structureView = createStructureComponent();
structureView.addPropertyChangeListener(new NodeSelectedListener());
}
return structureView;
}
public static void hideLabelAndLabelFor(JComponent component, String lab) {
JLabel label = findLabel(component, lab);
if(label != null) {
label.setVisible(false);
Component c = label.getLabelFor();
if(c != null) {
c.setVisible(false);
}
}
}
/** Called by UIManager when this look and feel is installed. */
@Override public void initialize() {
super.initialize();
defaults.initialize();
// create synth style factory
setStyleFactory(new SynthStyleFactory() {
@Override
public SynthStyle getStyle(JComponent c, Region r) {
return defaults.getStyle(c, r);
}
});
}