How to change the window title bar color - intellij-plugin

I want to know how to develop the idea plug-in, how to use the window, or how to define the child window of the idea
public class EncryptionAndDecryption extends AnAction {
#Override
public void actionPerformed(#NotNull AnActionEvent e) {
System.out.println("加密解密");
new test();
}
}
public class test {
private JButton button1;
private JPanel panel1;
public test() {
JFrame jFrame = new JFrame("test");
jFrame.setContentPane(panel1);
jFrame.setSize(500, 400);
//jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jFrame.setLocationRelativeTo(null);
// jFrame.setUndecorated(true);
jFrame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
jFrame.setVisible(true);
}
}
How to change title block color

Related

Android App: Replace default button background with custom background in a Dialog Fragment

What I'm trying to do is change the default backgrounds of a custom DialogFragment that I have written. Normally, I would do this by changing the XML layout file, however, for a DialogFragment these buttons don't exist in the layout file.
In essence, I'm trying to get access to the setPositiveButton, setNegativeButton and setNeutral buttons in order to modify them. Alternatively, I would next try to do this by getting them by id, however, since they aren't defined in a layout file, I do not have a corresponding id for them. I've found plenty examples of how to modify the rest of the layout, but I can't find anywhere that positive/neutral/negative buttons are modifiable.
Ideally, I could do this in the following block of code:
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
...
}
})
Thanks in advance.
Here is the code ... The button instance is valid only after the dialog created. Hope this helps you.
public static class CustomDialog extends DialogFragment
{
public static CustomDialog newInstance()
{
return new CustomDialog();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
super.onCreateDialog(savedInstanceState);
Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog dialog = builder.create();
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCEL",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
return dialog;
}
#Override
public void onStart()
{
super.onStart();
Button pButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
Button nButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE);
pButton.setBackgroundColor(getResources().getColor(R.color.Blue));
nButton.setBackgroundColor(getResources().getColor(R.color.Green));
}
}

Toggle implementation for custom RadioButton

I need to create a custom RadioButton without circle. Its a very simple class that extends Label and implements Toggle.
I added a mouse clicked handler :
private class MouseClickedHandler implements EventHandler<MouseEvent> {
#Override
public void handle(MouseEvent t) {
final Toggle toggle = (Toggle) t.getSource();
if (!toggle.isSelected()) {
getToggleGroup().selectToggle(toggle);
}
}
}
My problem is to set a default selected radio button.
If on one of the RadioButton I call setSelected(true) after its creation and after adding it to a ToggleGroup, when I launch the application if I click on other radio buttons in the group, the ToggleGroup does its job of deselecting except for that default one. I always end up with 2 radio buttons selected, the one on which I called setSelected(true) directly, and the one currently selected by a click.
I corrected it - Complete code :
public class RadioBtn extends Label implements Toggle {
private ObjectProperty<ToggleGroup> toggleGroup = null;
private BooleanProperty selectedProperty = null;
public RadioBtn {
initHandlers();
}
#Override
public ToggleGroup getToggleGroup() {
return toggleGroupProperty().get();
}
#Override
public void setToggleGroup(ToggleGroup tg) {
if (getToggleGroup() == null) {
toggleGroupProperty().set(tg);
}
getToggleGroup().getToggles().add(this);
}
#Override
public ObjectProperty<ToggleGroup> toggleGroupProperty() {
if (toggleGroup == null) {
toggleGroup = new SimpleObjectProperty<>();
}
return toggleGroup;
}
#Override
public boolean isSelected() {
return selectedProperty().get();
}
#Override
public void setSelected(boolean bln) {
selectedProperty().set(bln);
}
#Override
public BooleanProperty selectedProperty() {
if (selectedProperty == null) {
selectedProperty = new SimpleBooleanProperty();
}
return selectedProperty;
}
protected void initHandlers() {
if (getToggleGroup() != null) {
setOnMouseClicked(new ToggleGroupHandler());
}
}
private class ToggleGroupHandler implements EventHandler<MouseEvent> {
#Override
public void handle(MouseEvent t) {
final Toggle toggle = (Toggle) t.getSource();
if (!toggle.isSelected()) {
/*if(getToggleGroup().getSelectedToggle() != null) {
getToggleGroup().getSelectedToggle().setSelected(false);
}*/
getToggleGroup().selectToggle(toggle);
}
}
}
}

Display JColorChooser as frame and pass color value to buttons

Hello All and Thanks in advance.
I need JColorChooser to appear as the top panel in my window. I used a button in its place for formatting purposes.(See picture) I also need to pass chosen color value from colorchooser to chosen button in array. I have most of the structure complete but I am still pretty new to Java.
** I would like to also note that I do not need 'ok' or 'cancel' buttons in the colorchooser dialog because once you select a color you should be able to press as many buttons as you would like to change their colors to selected color.
View an image of my program
package main;
public class Main {
public static JPanel ToolPanel = new JPanel();
public static JPanel GridPanel = new JPanel();// Define the Panel that Holds 256 Button Array
public static JPanel FullPanel = new JPanel();
public static JButton button[] = new JButton[256];// Define button array for 256 buttons
private static JColorChooser colorChooser;
public static JButton ColorChooserButton = new JButton("This is where the JColorChooser(colorChooser) should go. ");
public static JFrame MaineWindow = new JFrame("Kola Color Crapper");
final static String ToolPanelString = "Tool Panel";
final static String GridPanelString = "Grid Panel";
public static ActionListener ButtonArrayActionListener = new ActionListener() {
public void actionPerformed(ActionEvent aef) {
if (aef.getSource() instanceof JButton) {
((JButton) aef.getSource()).setBackground(Color.blue);}}};
public static ActionListener ColorChooserButtonActionListener = new ActionListener() {
public void actionPerformed(ActionEvent aeef) {
String st="Welcome";
JOptionPane.showMessageDialog(null,st);
}};
public static void main( String[] args ){//Main (Run)
// setup the gui with buttons
CreateFullPanel();
CreateMaineWindow();
}
//CreateToolPanel() is just used to test formatting
public static void CreateToolPanel(){
ToolPanel.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
ToolPanel.setLayout(new GridLayout(1,0));
ColorChooserButton.addActionListener(ColorChooserButtonActionListener);
ToolPanel.add(ColorChooserButton);
ColorChooserButton.setToolTipText("This is a tool tip.");
}
public static void CreateFullPanel(){
CreateToolPanel();
CreateGridPanel();
//I want to insert CreateColorChooserPanel() where CreateToolPanel() is
// CreateColorChooserPanel();
}
public static void CreateGridPanel() {
GridPanel.setBorder(BorderFactory.createLineBorder(Color.blue, 2));
GridPanel.setLayout(new GridLayout(16, 16, 0, 0));
CreateButtonArray();// Create array of buttons
}
public static void CreateButtonArray(){
for (int i = 0; i < button.length; i++) {
button[i] = new JButton(Integer.toString(i + 1));
button[i].addActionListener(ButtonArrayActionListener);
GridPanel.add(button[i]);
GridPanel.setToolTipText("ToolTIp does not work");
}
}
public static void CreateMaineWindow(){
MaineWindow.setLayout(new GridLayout(2,1));//Main Window is resizable
MaineWindow.add(ToolPanel, ToolPanelString);
MaineWindow.add(GridPanel, ToolPanelString);
MaineWindow.setBounds(300,300,600,400);
MaineWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MaineWindow.pack();// pack all the contents of Main Window
MaineWindow.setVisible(true);//Show Main Window
}
public static void CreateColorChooserPanel(){
}
}

GWT popup is not centered when built within onClickHandler

My aim is to use GWT.runSync to load the popup contents only when required.
If I construct my widget as:
public class CreateButton extends Button {
public CreateButton() {
super("Create");
buildUI();
}
private void buildUI() {
final CreateWidget createWidget = new CreateWidget();
final PopupPanel popupPanel = new PopupPanel(false);
popupPanel.setWidget(createWidget);
popupPanel.setGlassEnabled(true);
popupPanel.setAnimationEnabled(true);
addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
popupPanel.center();
}
});
}
}
Then the popup will be centered correctly.
If I build the popup within the clickHandler:
public class CreateButton extends Button {
public CreateButton() {
super("Create");
buildUI();
}
private void buildUI() {
#Override
public void onClick(ClickEvent event) {
final CreateWidget createWidget = new CreateWidget();
final PopupPanel popupPanel = new PopupPanel(false);
popupPanel.setWidget(createWidget);
popupPanel.setGlassEnabled(true);
popupPanel.setAnimationEnabled(true);
addClickHandler(new ClickHandler() {
popupPanel.center();
}
});
}
}
The popup will not center correctly. I have tried using setPositionAndShow, however the supplied offsets are 12, even though the CreateWidget is actually about 200px for both width and height.
I want to use the second method so I can eventually use GWT.runAsync within the onClick as CreateWidget is very complex.
I am using GWT-2.1.1
Seems to work by delaying the call to center. Perhaps a once off Timer would work as well. Delaying the call also works when wrapping buildUI within GWT.runAsync
public class CreateButton extends Button {
public CreateButton() {
super("Create");
buildUI();
}
private void buildUI() {
#Override
public void onClick(ClickEvent event) {
final CreateWidget createWidget = new CreateWidget();
final PopupPanel popupPanel = new PopupPanel(false);
popupPanel.setWidget(createWidget);
popupPanel.setGlassEnabled(true);
popupPanel.setAnimationEnabled(true);
addClickHandler(new ClickHandler() {
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
#Override
public boolean execute() {
popupPanel.center();
return false;
}
}, 50); //a value greater than 50 maybe needed here.
});
}
}
}
}

SurfaceView Tutorial problems

I found a tutorial and it looks like this:
package com.djrobotfreak.SVTest;
public class Tutorial2D extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new Panel(this));
}
class Panel extends SurfaceView implements SurfaceHolder.Callback {
private TutorialThread _thread;
public Panel(Context context) {
super(context);
getHolder().addCallback(this);
_thread = new TutorialThread(getHolder(), this);
}
#Override
public void onDraw(Canvas canvas) {
Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(_scratch, 10, 10, null);
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
_thread.setRunning(true);
_thread.start();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// simply copied from sample application LunarLander:
// we have to tell thread to shut down & wait for it to finish, or else
// it might touch the Surface after we return and explode
boolean retry = true;
_thread.setRunning(false);
while (retry) {
try {
_thread.join();
retry = false;
} catch (InterruptedException e) {
// we will try it again and again...
}
}
}
}
class TutorialThread extends Thread {
private SurfaceHolder _surfaceHolder;
private Panel _panel;
private boolean _run = false;
public TutorialThread(SurfaceHolder surfaceHolder, Panel panel) {
_surfaceHolder = surfaceHolder;
_panel = panel;
}
public void setRunning(boolean run) {
_run = run;
}
#Override
public void run() {
Canvas c;
while (_run) {
c = null;
try {
c = _surfaceHolder.lockCanvas(null);
synchronized (_surfaceHolder) {
_panel.onDraw(c);
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
_surfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
}
}
and it does not work, no matter what I do. I am trying to convert my code to surfaceview but I cant find any surfaceview programs that even work (besides the android-provided ones). Does anyone know what the error even is saying?
Here is my logcat info: http://shrib.com/oJB5Bxqs
If you get a ClassNotFoundException, you should check the Manifest file.
Click on the Application tab and look on the botton right side under "Attributes for".
If there is a red X mark under your Class Name, then click on the "Name" link and locate the correct class to load.